Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

COLLECTIONS.DEFAULTDICT(set)

defaultdict means that if a key is not found in the dictionary,
then instead of a KeyError being thrown, a new entry is created. 
The type of this new entry is given by the argument of defaultdict.

For example:

somedict = {}
print(somedict[3]) # KeyError

someddict = defaultdict(int)
print(someddict[3]) # print int(), thus 0

>>> from collections import defaultdict
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
3+8 =