首页 > 编程 > Python > 正文

python统计词频的方法

2019-11-08 18:23:20
字体:
来源:转载
供稿:网友

利用Counter的字典

from collections import Countertotal_counts = Counter()sentence='hello world'for Word in sentence.split(" "): total_counts[word] += 1PRint(total_counts)

输出

Counter({'hello': 1, 'world': 1})
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表