-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion 10.py
31 lines (20 loc) · 861 Bytes
/
Question 10.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
# 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
#MY SOLUTION
list_of_words = []
user_words = input('Type something interesting: ').split()
for words in user_words:
list_of_words.append(words)
output = sorted(set(list_of_words))
print(' '.join(output))
#COURSE SOLUTION
word = input().split()
for i in word:
if word.count(i) > 1: #count function returns total repeatation of an element that is send as argument
word.remove(i) # removes exactly one element per call
word.sort()
print(" ".join(word))