不知何故without_E
函數不起作用。我收到了整個名單。但我只希望檢測字母'e'
。此外,當我打印清單時,我收到的形式是[words]
,而不是"words"
。這是正常的行爲嗎?這些功能正在從wordlist
文件中讀取。Python條件中的函數without_E無法正常工作
# Display words without letter "e"
def without_E(word):
for ch in word:
if ch == 'e' or ch == 'E':
print "here" * 5
return False
return True
def percentage_words():
i = 0
j = 0
fin = open("wordlist")
for line in fin:
i += 1
word = line.split()
if without_E(word):
j += 1
# print word
percentage = (j * 100)/i
print percentage
def main():
# word_list()
# long_words20()
# without_E()
percentage_words()
if __name__ == "__main__":
main()