def __getitem__(self, key): if key not in self.keys(): val = self.__class__() self.__setitem__(key, val) else: val = dict.__getitem__(self, key) return val
def __getitem__(self, idx): try: return dict.__getitem__(self, idx) except KeyError: return 0