Created
April 7, 2020 04:04
-
-
Save y56/93cecc3d439d83597f86e8866b4e73ef to your computer and use it in GitHub Desktop.
collections.defaultdict()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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