forked from fenyx-it-academy/class2-functions-week04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.alphabetical_order.py
35 lines (26 loc) · 1015 Bytes
/
9.alphabetical_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Write a function that takes an input form user
which separates the words hyphen icon(-)
and sort the words alphabetical order
and then adds hyphen icon (-) between them
and gives the output of it.
For example: input= green-red-yellow-black-white
output= black-green-red-white-yellow
"""
# define a function named alphabetical_order
def alphabetical_order(ordered_letter):
""" This function sorts the words alphabetical order """
# user inputs were splited into a list,name words_list, use "-" as a separator
words_list = ordered_letter.split("-")
# words_list was sorted alphabetically
words_list.sort()
# define a seperator
separator = "-"
# add hyphen icon (-) between sorted list items
return (separator.join(words_list))
user_letter = input("Please enter your words and use hyphen icon(-) to separete them :")
# for example
if user_letter == "":
user_letter = "green-red-yellow-black-white"
print(alphabetical_order(user_letter))
# The End