我是靠谱客的博主 默默钢笔,这篇文章主要介绍python3内置函数一Counter列表里面元素的统计,现在分享给大家,希望可以做个参考。

列表里面元素的统计

from collections import Counter
text1 = "There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream"
text2 = text1.split(' ')
print(Counter(text2).most_common(1))

首字母大写(正则)

只是提供一种思路
import re
text1 = "There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream"
text2 = text1.split(' ')
print([w for w in text2 if re.search(r'^[A-Z]', w)])

最后

以上就是默默钢笔最近收集整理的关于python3内置函数一Counter列表里面元素的统计的全部内容,更多相关python3内置函数一Counter列表里面元素内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部