python 找出序列中出现次数最多的元素方法
2017-09-08 16:32
671 查看
from collections import 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' ]
print (Counter(words))
Counter({'eyes': 8, 'the': 5, 'look': 4, 'into': 3, 'my': 3, 'around': 2, 'not': 1, "don't": 1, "you're": 1, 'under': 1})
print (Counter(words).most_common(4)) [('eyes', 8), ('the', 5), ('look', 4), ('into', 3)]
原文链接
相关文章推荐
- python 找出序列中出现次数最多的元素方法。
- Python cookbook(数据结构与算法)找出序列中出现次数最多的元素算法示例
- python找出序列中出现次数最多的元素之Counter对象
- Python实用黑科技——找出序列里面出现次数最多的元素
- 利用Python找出序列中出现最多的元素示例代码
- [PY3]——找出一个序列中出现次数最多的元素/collections.Counter 类的用法
- java找出一个数组中出现次数最多的那个元素
- python(dict字典相关知识以及小例子:生成一个列表,存放100个随机整数,找出出现次数最多的数字)
- 347. Top K Frequent Elements(找出数组中出现次数最多的前k个元素)
- 找出一个列表中出现次数最多的元素
- Python第三方库——Numpy_怎么得到向量中出现次数最多的元素值?
- java找出一个数组中出现次数最多且最大的那个元素
- 1.12.在序列中查找出现次数最多的元素
- Python找出list中最常出现元素的方法
- [00012] 序列中出现次数最多的元素
- 输出列表中出现次数最多的元素 分类: python 2013-01-15 15:25 990人阅读 评论(0) 收藏
- 找出数组中出现次数最多的前k个元素[leetcode题]
- python 获得列表中每个元素出现次数的最快方法
- java 找出n个元素数组中重复次数最多的数(假设出现次数大于n/2)
- 找出数组里面元素出现次数最多的问题