Skip to content

Instantly share code, notes, and snippets.

@y56
Created April 7, 2020 04:04
Show Gist options
  • Save y56/93cecc3d439d83597f86e8866b4e73ef to your computer and use it in GitHub Desktop.
Save y56/93cecc3d439d83597f86e8866b4e73ef to your computer and use it in GitHub Desktop.
collections.defaultdict()
https://docs.python.org/3/library/collections.html#defaultdict-objects
dd=collections.defaultdict(lambda: [1])
# defaultdict(<function __main__.<lambda>()>, {})
xx=dd['1']
dd
# defaultdict(<function __main__.<lambda>()>, {'1': [1]})
xx
# [1]
xx[0]=100
xx
# [100]
dd
# defaultdict(<function __main__.<lambda>()>, {'1': [100]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment