-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion10.py
More file actions
23 lines (18 loc) · 796 Bytes
/
question10.py
File metadata and controls
23 lines (18 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
Question 10
Level 2
Question:
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
Suppose the following input is supplied to the program:
hello world and practice makes perfect and hello world again
Then, the output should be:
again and hello makes perfect practice world
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
We use set container to remove duplicated data automatically and then use sorted() to sort the data.
'''
input_str = input(
'enter the sentence to remove the duplicates and sort them alphabettically: ')
inputSet = set(input_str.strip().split(' '))
result = sorted(inputSet)
print(result)