Python code question 10

和自甴很熟 提交于 2021-01-21 21:53:45

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.

#!/usr/bin/env python
# encoding: utf-8
'''
@author:
@contact:
@software:
@file: q10.py
@time: 2021/1/14 4:28 下午
@desc:solution to q10
'''


'''
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_content = input()
origin_input = input_content.split(' ')
set_of_input = set(origin_input)
print(' '.join(sorted(set_of_input)))




 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!