我正在写一个程序,它从50,000个单词的文件中读取,它需要获得没有字母'e'的单词的百分比。我可以让程序打印所有没有e的单词,但是我想把它们附加到列表中,以便我可以得到列表中元素的总和。我现在拥有的每一次运行结果都是0。它也产生了正确的总量。对不起,我不是Python中最好的。从python中的文件中附加特定单词到列表
f=open("hardwords.txt")
def has_no_e(f):
words = []
sum_words= len(words)
total = sum(1 for s in f)
print total
print sum_words
letter = 'e'
for line in f:
for l in letter:
if l in line:
break
else:
words.append(line)
has_no_e(f)
请提供您的输入样本。 –