1、from co盟敢势袂llections import Counterabc = [1,2,454,3,6,3,1,3,5,6,8荑樊综鲶,4,3,8,4,2,1,2,3,]counts = Counter(abc)print(counts)引进模块函数,然后直接统计每个数字出现的次数。
2、uuu = counts[6]print(uuu)我们可以找到指定的数字出现的次数。
3、none = counts[322]print(none)如果没有的数字会显示0。
4、counts[454] = 10print(counts[454])print(counts)可以直接对数字出现的次数进行更改。
5、counts[454] = 0print(counts[454])print(counts)可以吧次数更改为0次。
6、del counts[454]print(counts)当然可以直接移除数字。
7、ooo = list(counts.elements())print(ooo)可以整理一下为一个新的列表。
8、i = counts.most_common(2)print(i)可以查找出现次数最频繁的。
9、i = counts.most_common(2)print(i[0][0])出现次数最频繁的具体哪个数字,不需要其他数据也可以这样显示。
10、ad蟠校盯昂d = counts + countsprint(add)su = counts - countspr足毂忍珩int(su)mul = counts * countsprint(mul)可以进行加减法,但是不能相乘。