NDOJ/judge/utils/cachedict.py

9 lines
217 B
Python
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
class CacheDict(dict):
def __init__(self, func):
super(CacheDict, self).__init__()
self.func = func
def __missing__(self, key):
self[key] = value = self.func(key)
return value