s = "aabbccc"
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 0
for i in s:
d[i] = d.get(i, 0) + 1
print(d)
# {'a': 2, 'b': 2, 'c': 3}
s = "aabbccc"
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 0
for i in s:
d[i] = d.get(i, 0) + 1
print(d)
# {'a': 2, 'b': 2, 'c': 3}
转载于:https://www.cnblogs.com/iiiiiher/p/10174329.html