Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python default dictonary

from collections import defaultdict

d_int = defaultdict(int)
d_list = defaultdict(list)

def foo():
  return 'default value'
 
d_foo = defaultdict(foo)

>>> d_int
defaultdict(<type 'int'>, {})
>>> d_list
defaultdict(<type 'list'>, {})
>>> d_foo
defaultdict(<function foo at 0x7f34a0a69578>, {})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #default #dictonary
ADD COMMENT
Topic
Name
5+3 =