assignment 8.4

编写一个程序,打开romeo.txt文件,按行读取。对每一行使用split函数,将其分解成一系列的单词列表。对于每一个单词,检查它是否已经存在于列表之中,若单词还未出现在列表中,把它添加进来
按字母顺序输出最终的单词清单

代码如下:

1
2
3
4
5
6
7
8
9
fname = raw_input("Enter file name: ")
fh = open(fname)
text = fh.read()
words = text.split()
lst = list()
for word in words:
lst.append(word)
lst = sorted(set(words))
print lst