-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp6-b.py
18 lines (15 loc) · 842 Bytes
/
p6-b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
''' 6.b.
Write a program that accepts a comma separated sequence of words as input
and prints the words in a comma-separated sequence after sorting them
alphabetically.
'''
# Suppose the following input is supplied to the program:
# banana,raspberry,apricot,mango,apple,pomegranate"
# Then, the output should be:
# apple,apricot,banana,mango,pomegranate,raspberry
print("Enter a comma separated line, don't add any spaces: ")
line = input() # enter input through keyboard
tokenized_line = line.split(',') # split words where there is a comma
sorted_tokenized_line = sorted(tokenized_line) # sord words alphabetically
sorted_line = ','.join(sorted_tokenized_line) # join words with comma
print(sorted_line) # print onto console