name = "helloworld"
dict1 = {}
for i in name:
sum = 1
if i not in dict1:
dict1[i] = sum
else:
sum =sum+1
dict1[i]+=1
print(dict1)
for key,values in dict1.items():
print("字母%c出现的次数是%d次"%(key,values))
结果是:
{'h': 1, 'e': 1, 'l': 3, 'o': 2, 'w': 1, 'r': 1, 'd': 1}
字母h出现的次数是1次
字母e出现的次数是1次
字母l出现的次数是3次
字母o出现的次数是2次
字母w出现的次数是1次
字母r出现的次数是1次
字母d出现的次数是1次
进程已结束,退出代码0