[py]使用字典get方法做数据统计时间:2023-03-09 20:56:16 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}