a = [1, 2, 3, 1, 1, 3, 6, 9, 6, 9, 9, 1, 2, 2, 2, 6, 6, 6] b = {} for j in c: if j in b.keys(): b[j] = b[j] + 1 else: b[j] = 1 for k in b.keys(): print(“值”, k, "&", “出现次数”, b[k])
字典计算列表中的数字出现次数
最新推荐文章于 2024-11-13 17:24:18 发布
a = [1, 2, 3, 1, 1, 3, 6, 9, 6, 9, 9, 1, 2, 2, 2, 6, 6, 6] b = {} for j in c: if j in b.keys(): b[j] = b[j] + 1 else: b[j] = 1 for k in b.keys(): print(“值”, k, "&", “出现次数”, b[k])