首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python 计算元素出现的次数

python 计算元素出现的次数

作者头像
用户5760343
发布2019-09-25 11:44:07
发布2019-09-25 11:44:07
2.7K0
举报
文章被收录于专栏:sktjsktj

collections.Counter

words = [ 'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes', 'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', 'the', 'eyes', "don't", 'look', 'around', 'the', 'eyes', 'look', 'into', 'my', 'eyes', "you're", 'under' ] from collections import Counter word_counts = Counter(words)

出现频率最高的3个单词

top_three = word_counts.most_common(3) print(top_three)

Outputs [('eyes', 8), ('the', 5), ('look', 4)]

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.09.24 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • collections.Counter
  • 出现频率最高的3个单词
  • Outputs [('eyes', 8), ('the', 5), ('look', 4)]
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档