python collections 的使用
持续更新
Counter:
用来进行计数的类。
from collections import Counter
c = Counter(["hello", "hi", "hello"]) # 参数是可迭代的对象
# Counter({'hello': 2, 'hi': 1})
# c["hello"] >> 2
# c["no"] >> 0
持续更新
Counter:
用来进行计数的类。
from collections import Counter
c = Counter(["hello", "hi", "hello"]) # 参数是可迭代的对象
# Counter({'hello': 2, 'hi': 1})
# c["hello"] >> 2
# c["no"] >> 0