-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPy_Exercise-10.py
More file actions
39 lines (29 loc) · 979 Bytes
/
Py_Exercise-10.py
File metadata and controls
39 lines (29 loc) · 979 Bytes
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
36
37
38
39
# -------------------------------------------------------------------------
# Author: Quang Tran
# Date: May 10th, 2019
# -------------------------------------------------------------------------
"""
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
"""
print("Please enter a string: ")
user_input = input().split(" ")
result = []
for word in user_input:
if word not in result:
result.append(word)
else:
continue
result.sort()
print("\nHere is your new sorted string: ")
print(" ".join(result))
"""
FASTER WAY - but does not look clean:
user_input = input().split(" ")
print(" ".join(sorted(list(set(user_input)))))
"""