Goodies of the Python Standard Library¶

from collections import Counter

data = [1, 2, 3, 1, 2, 4, 5, 6, 2]

counter = Counter(data)
print(f"type: {type(counter)}, counter: {counter}")

print(f"count of twos: {counter[2]}")
print(f"count of tens: {counter[10]}")  # zero for non existing

print(f"counter is a dict: {isinstance(counter, dict)}")