每当我尝试运行该程序时,Python IDLE都会通过告诉我它没有响应并且必须关闭来做出响应。有关如何改进此代码以使其按我想要的方式工作的任何建议?python,从文本文档创建一个过滤列表
#open text document
#filter out words in the document by appending to an empty list
#get rid of words that show up more than once
#get rid of words that aren't all lowercase
#get rid of words that end in substring 'xx'
#get rid of words that are less than 5 characters
#print list
fin = open('example.txt')
L = []
for word in fin:
if len(word) >= 5:
L.append(word)
if word != word:
L.append(word)
if word[-2:-1] != 'xx':
L.append(word)
if word == word.lower():
L.append(word)
print L
多大是example.txt? – geoffspear
(另外,你的逻辑还没有完成;你没有摆脱满足其中一个标准的单词;你保留每个单词的一个副本,以符合你不违反的每个标准。) – geoffspear
文本文档非常大,是一本书的几个章节。 是的,我需要很多的帮助:( – SWebbz