l = list(range(1, 4)) #### 0:{1}, 1:{2}, 2:{3} random.shuffle(l) print(l[1]) 
  • four
    Why did you need it? - tutankhamun
  • You can write a function that will refer to a sheet with subtraction from the index of the unit. But why?? - AivanF.

1 answer 1

You are guaranteed to do something bad, nonetheless purely from an academic point of view: you can create a separate class that inherits from the list and override the behavior of the necessary methods, for example __getitem__ , like this:

 class MyList(list): def __getitem__(self, index): return super(MyList, self).__getitem__(index - 1) >>> my_list = MyList(['a', 'b', 'c']) >>> mylist[1] 'a' 

Only it is necessary to decide what exactly to do with 0 and negative indices.