Advertisement
RederickDeathwill

List with wrong starting index, yeah...

Sep 18th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class ListWithWrongStartingIndex(list):
  2.    
  3.     def __init__(self):
  4.         super().__init__(self)
  5.        
  6.     def __getitem__(self, index):
  7.         return list.__getitem__(self, index-1)
  8.        
  9.     def __setitem__(self, index, whatever):
  10.         list.__setitem__(self, index-1, whatever)
  11.        
  12. x = ListWithWrongStartingIndex()
  13. x.insert(1, "whatever")
  14. x.insert(2, "whatever again")
  15. print(x[1])
  16. print(x[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement