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)])

你可能感兴趣的:(python内置函数)