s = 'Life was like a box of chocolates. You never know what you are going to get.'
d = {}
for c in s:
d[c] = (d[c] + 1) if (c in d) else (1)
print(d)
字符串的字符计数
最新推荐文章于 2024-05-14 00:26:02 发布
s = 'Life was like a box of chocolates. You never know what you are going to get.'
d = {}
for c in s:
d[c] = (d[c] + 1) if (c in d) else (1)
print(d)