repl.it
@lakshayarora7/

CoolSwiftMussaurus

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
# Python script which prompts the user for a sequence of space-separated words, and outputs the sorted sequence with no duplicates. For example, if the user inputs 'apple aardvark apple ball cat', then the output should be 'aardvard apple ball cat'. You may use builtin sort() to sort the words.

sequence = input("Please enter a sequence of space-separated words: ")	# apple aardvark apple ball cat

words = sequence.split(" ")												# ['apple', 'aardvark', 'apple', 'ball', 'cat']

uniqueWords = set(words)												# {'aardvark', 'ball', 'apple', 'cat'}
sortedWords = sorted(uniqueWords)										# ['aardvark', 'apple', 'ball', 'cat']

print(" ".join(sortedWords))											# aardvark apple ball cat
Fetching token
?