Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

defaultdict python

>>> 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
...
defaul
Source by www.accelebrate.com #
 
PREVIOUS NEXT
Tagged: #defaultdict #python
ADD COMMENT
Topic
Name
4+1 =