Created
October 10, 2021 19:57
-
-
Save thomashikaru/89405835f0f218ad14ad3648a2332cd3 to your computer and use it in GitHub Desktop.
This file contains 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
from collections import defaultdict | |
d = defaultdict(int) | |
print(d["Alice"]) # prints 0 | |
d["Bob"] += 1 | |
print(d["Bob"]) # prints 1 | |
d = defaultdict(list) | |
d["John"].append("eggs") | |
print(d["John"]) # prints ["eggs"] | |
d = defaultdict(lambda: 100) | |
d["Alice"] += 1 | |
print(d["Alice"]) # prints 101 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment