python collections 的使用教程

python collections 的使用

持续更新

Counter:

用来进行计数的类。

from collections import Counter

c = Counter(["hello", "hi", "hello"])  # 参数是可迭代的对象

# Counter({'hello': 2, 'hi': 1})
# c["hello"] >> 2
# c["no"] >> 0

猜你喜欢

转载自blog.csdn.net/hpulfc/article/details/81112201