我正在寫一個程序,它從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)
請提供您的輸入樣本。 –