首页 > 代码库 > Python 过滤重复单词

Python 过滤重复单词

描述:一个英文句子仅由单词、逗号、句号、空格组成。要求过滤句子中的重复单词,例如:输入where there is a will, there is a way.

输出:where there is a will way

str = raw_input("");a = []str = str.replace(",", "").replace(".", "")a = str.split(" ")b = sorted(set(a),key=a.index)for x in b:    if x !="":        print x,

  

Python 过滤重复单词