📅  最后修改于: 2022-03-11 14:45:43.093000             🧑  作者: Mango
>>> from collections import defaultdict
>>> food_list = 'spam spam spam spam spam spam eggs spam'.split()
>>> food_count = defaultdict(int) # default value of int is 0
>>> for food in food_list:
... food_count[food] += 1 # increment element's value by 1
...
defaultdict(, {'eggs': 1, 'spam': 7})
>>>