class ddict(dict): def __getitem__(self, key): try: return super().__getitem__(key) except KeyError: v = self[key] = ddict() return v d = ddict() d[1][2][3][4] = 5 print(d[1][2][3][4])
class ddict(dict): def __getitem__(self, key): try: return super().__getitem__(key) except KeyError: v = self[key] = ddict() return v d = ddict() d[1][2][3][4] = 5 print(d[1][2][3][4])