统计每个单词的个数
原始数据:
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)
标签:count,s1,练习,个数,统计,baby,sb,hello,kevin From: https://www.cnblogs.com/zenopan101861/p/18120337