大家好,这是我要运行的代码。我不是计算机科学家,我知道这是一个简单的答案,我只是没有工具来回答它。我正在尝试将此列表打印到文本文件中。如果我打印到屏幕上,它会起作用。我得到的错误是:“TypeError:期望一个字符缓冲区对象”
这是代码
input = open('Tyger.txt', 'r')
text = input.read()
wordlist = text.split()
output_file = open ('FrequencyList.txt','w')
wordfreq = [wordlist.count(p) for p in wordlist]
#Pair words with corresponding frequency
dictionary = dict(zip(wordlist,wordfreq))
#Sort by inverse Frequency and print
aux = [(dictionary[key], key) for key in dictionary]
aux.sort()
aux.reverse()
for a in aux: output_file.write(a)
谢谢!