a = [1, 2, 3, 2, 1, 5, 6, 5, 5, 5] b = set(a) for each_b in b: count = 0 for each_a in a: if each_b == each_a: count += 1 print(each_b, ": ", count)
===============================
结果:
1 : 2 2 : 2 3 : 1 5 : 4 6 : 1