今天爱分享给大家带来 python3 统计一个list的词频【附代码】,希望能帮助到大家。
做统计机器学习经常需要统计,这里我来分享一下怎样统计一个list里面每个字符串的频率:
from collections import Counter word_count=['I','am','from','China',',','I','Love','my','country','!','!','!'] counter = Counter(word_count) dictionary=dict(counter) # get to k most frequently occuring words k=10 res=counter.most_common(k) print(res)
输出为:
[('!', 3), ('I', 2), ('am', 1), ('from', 1), ('China', 1), (',', 1), ('Love', 1), ('my', 1), ('country', 1)]
原文链接:https://itblood.website/1590.html,转载请注明出处。

![【ACT/中文/动态】邪神祷告UnHolY PraYeR 2025年10月動作確認版 官方中文版[更新]【电脑/1.3G】](/wp-content/uploads/replace/2025/11/05/43d3d2dea3fe890b0aa1d9eddc4fbf2c.webp)