Python - sum of all counts in collections.Counter
Python tip:
You can compute the sum of all the counts from a
Counter
with total():from collections import Counter pencil_stock = Counter({"Red": 17, "Blue": 5, "Green": 9}) print(pencil_stock.total()) # -> 31