2
爲什麼我總是收到屬性的錯誤不會消失
AttributeError: 'dict_keys' object has no attribute 'sort'
或我的代碼?我怎樣才能解決這個問題?
import string
infile = open('alice_in_wonderland.txt', 'r')
text = infile.readlines()
counts = {}
for line in text:
for word in line:
counts[word] = counts.get (word, 0) +1
'''
if word != " ":
if word != ".":
'''
word_keys = counts.keys()
word_keys.sort()
infile.close()
outfile = open("alice_words.txt", 'w')
outfile.write("Word \t \t Count \n")
outfile.write("======================= \n")
for word in word_keys:
outfile.write("%-12s%d\n" % (word.lower(), counts[word]))
outfile.close()
我不確定還有什麼要做。
哇,非常感謝,你是男人。出於某種原因,我正試圖修復9-11行。 – user3490645