I have some code to define a class in which the main entity is a dictionary. For example:
class MyDictionary:
def __init__(self):
self.__my_dict = {'a': 1,
'b': 2,
'c': 3}
def __getitem__(self, item):
return self.__my_dict[item]
def __len__(self):
return len(self.__my_dict)
def keys(self):
# ?
def items(self):
# ?
my_dict = MyDictionary
for key, value in my_dict.items():
print([key, value])
for key in my_dict.keys():
print(my_dict[key])
How should I define the member functions such that I can use the []
, len()
, keys()
, items()
operators on the class instance my_dict
as if it were a dictionary?