Program - class to show implementation of custom sequence of list
Topic: Program - class to show implementation of custom sequence of list
Solution
class CustomList: """ This is the space to do documentation related to class. """ def __init__(self): self.list_ = [1,2,3,4] def __len__(self): return len(self.list_) def __getitem__(self, i): if isinstance(i, int): if i<0: i = len(self.list_) + i if i<0 or i>=len(self.list_): raise IndexError('Invalid Input') else: return self.list_[i]
List all Python Programs