Skip to content

Instantly share code, notes, and snippets.

@aman-tiwari
Created January 11, 2015 20:33
Show Gist options
  • Save aman-tiwari/870de769bf222626d3d1 to your computer and use it in GitHub Desktop.
Save aman-tiwari/870de769bf222626d3d1 to your computer and use it in GitHub Desktop.
class OptimisticDict(dict):
def __init__(self, factory_func):
self.factory_func = factory_func
super(OptimisticDict, self).__init__()
def __missing__(self, key):
self[key] = self.factory_func(key)
return self.factory_func(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment