我已經在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