]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/util/autovivifying.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / util / autovivifying.py
1 class Dict(dict):
2     def __init__(self, *args, vivifier=lambda k: None, **kwargs):
3         self.vivifier = vivifier
4
5         dict.__init__(self, *args, **kwargs)
6
7     def __getitem__(self, key):
8         if key not in self:
9             dict.__setitem__(self, key, self.vivifier(key))
10
11         return dict.__getitem__(self, key)

Community Data Science Collective || Want to submit a patch?