初学Python 统计字符串每个字母出现次数
a = input("请输入字符串:")
b = list(a.lower()) #将输入的字符全部转换为小写字母
c = {} #建立一个空字典
for i in b: #for循环遍历出结果
c[i] = b.count(i)
print(c)
输出结果:
初学Python 统计字符串每个字母出现次数
a = input("请输入字符串:")
b = list(a.lower()) #将输入的字符全部转换为小写字母
c = {} #建立一个空字典
for i in b: #for循环遍历出结果
c[i] = b.count(i)
print(c)
输出结果: