Counter
Counter,最主要的作用就是计算“可迭代序列中”各个元素(element)的数量,并且按照倒序排列放出来
from collections import Counter
if __name__ == '__main__':
list =['a', 'b', 'b','b','b','b','c','c']
print(Counter(list))
结果:
Counter({'b': 5, 'c': 2, 'a': 1})
2022-11-10 15:37:55
Counter,最主要的作用就是计算“可迭代序列中”各个元素(element)的数量,并且按照倒序排列放出来
from collections import Counter
if __name__ == '__main__':
list =['a', 'b', 'b','b','b','b','c','c']
print(Counter(list))
结果:
Counter({'b': 5, 'c': 2, 'a': 1})
下一篇:PHP for 循环