小练习统计个数

统计每个单词的个数

原始数据:

s1 = 'kevin say hello hello hello big baby baby baby sb sb kevin kevin'

s1 = 'kevin say hello hello hello big baby baby baby sb sb kevin kevin'

统计每个字母个数

s2 =set(s1)

print(s2)

count_dict = {}
for i in s2:
count_dict[i] = s1.count(i)
print(count_dict)

统计每个单词个数

s3 = set(s1.split(' '))
countword = {}
for i in s3:
countword[i] = s1.count(i)

print(countword)

posted @ 2024-04-08 08:52  zenopan  阅读(2)  评论(0编辑  收藏  举报