387
Pe
python-exercices / files
python-exercices / level_two / ex_10.py
845 bytes
1#!/usr/bin/env python3 2 3# Question: 4# Write a program that accepts a sequence of whitespace separated words as input and prints 5# the words after removing all duplicate words and sorting them alphanumerically. 6# Suppose the following input is supplied to the program: 7# hello world and practice makes perfect and hello world again 8# Then, the output should be: 9# again and hello makes perfect practice world 10 11# Hints: 12# In case of input data being supplied to the question, it should be assumed to be a console input. 13# We use set container to remove duplicated data automatically and then use sorted() to sort 14# the data. 15 16 17def word_sorter(): 18 raw_text = input('Enter a list of words sperated by whitespace\n') 19 unique_words = set(raw_text.split()) 20 print(" ".join(sorted(unique_words))) 21 22 23if __name__ == '__main__': 24 word_sorter()