[Python] Finding the most common elements in an iterable
Python in The an Elements Common most Iterable
2023-09-14 08:59:17 时间
>>> import collections >>> # Tally occurrences of words in a list >>> cnt = collections.Counter() >>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']: ... cnt[word] += 1 >>> cnt Counter({'blue': 3, 'red': 2, 'green': 1}) >>> c = collections.Counter('helloworld') >>> c Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1}) >>> c.most_common(3) [('l', 3), ('o', 2), ('e', 1)]
相关文章
- python qt是什么_初识Python与Qt「建议收藏」
- python编程是啥-Python编程「建议收藏」
- Python&R语言-python和r相遇
- Python:过滤序列的filter()函数
- python表情代码_Python实现表情包的代码实例[通俗易懂]
- python使用opencv如何保存图片_OpenCV Python 保存图片
- ROS2机器人编程简述humble-第三章-BUMP AND GO BEHAVIOR IN PYTHON .4
- 基础入门详解Python 操作 Excel 自动化办公指南
- ORA-31053: The value of the depth argument in the operator cannot be negative ORACLE 报错 故障修复 远程处理
- ORA-48405: The option in the command is invalid ORACLE 报错 故障修复 远程处理
- ORA-48444: The single “.” and “*” cannot appear in the middle of the path ORACLE 报错 故障修复 远程处理
- ORA-13703: The snapshot pair [string, string] for database_id string and instance_id string are not found in the current repository. ORACLE 报错 故障修复 远程处理
- 利用python 统计源码行数详解编程语言
- python 三级菜单
- Oracle Achieves 100% Success: The Strongest Database System in the Market(oracle100)
- Linux下运行Python脚本的步骤简介(linux如何运行python脚本)
- MySQL中IN查询的使用及效率优化(mysql中in的0)