假设统计 s="aabbccc"中,每个字符出现的次数:
结果应当为:"a":2, "b":2, "c":3
s = "aabbccc"
dic = {}
for ch in s:
dic[ch]=1+dic.get(ch,0)
print dic
假设统计 s="aabbccc"中,每个字符出现的次数:
结果应当为:"a":2, "b":2, "c":3
s = "aabbccc"
dic = {}
for ch in s:
dic[ch]=1+dic.get(ch,0)
print dic