我已经在Python中运行下面的代码以从文本文件生成单词列表和它们的计数。我将如何去滤除我的“frequency_list”变量中只包含1的单词?在Python中更改字典/键
另外,我怎么会在底部导出打印语句循环到CSV
预先感谢提供任何帮助。
import re
import string
frequency = {}
document_text = open('Words.txt', 'r')
text_string = document_text.read().lower()
match_pattern = re.findall(r'\b[a-z]{3,15}\b', text_string)
for word in match_pattern:
count = frequency.get(word,0)
frequency[word] = count + 1
frequency_list = frequency.keys()
for words in frequency_list:
print (words, frequency[words])
迭代关键值对使用[one这些'''dict'''方法](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict);测试你的状况的价值;将符合要求的密钥存储在容器中(如列表);使用[csv模块](https://docs.python.org/3/library/csv.html)写入csv – wwii