I am trying to code a set, inheriting from a list just for practice. I have the following code:
class MyList(list):
def __init__(self):
list.__init__(self)
self.idx = 0
def append(self, *args):
for i in args:
try:
self.__getitem__(i)
except AttributeError:
self.__setitem__(self.idx, i)
def __repr__(self):
# print all items
pass
What I am trying to do with the try
and except
statements is to check if an item is already in the list, however I know that that won't work as all self.__getitem__()
uses the index to look for an item. However, what I really wanted to do was to check if something passed in already exists inside the list. In short, how does one access all the data of an inherited class?