from typing import TypeVar, Generic, List E = TypeVar('E') class ArrayListSet(Generic[E],List[E]): def __hash__(self): hashCode = 1 for e in self: hashCode += 0 if e == None else hash(e) return hashCode def __eq__(self, o) -> bool: if not isinstance(o, ArrayListSet): return False list2:ArrayListSet = o if len(self) != len(list2): return False for e1 in self: if not e1 in list2: return False return True # we can't declare index:int , python says mismatch with superclass! def __setitem__(self, index, element): if element in self: self.remove(element) return super().__setitem__(index, element) def append(self, e) : if e in self: return False return super().append(e) def insert(self, index, element): if element in self: return; super().insert(index, element) def extend(self, c) : for e in c: self.append(c)