Python make a circular list to get out of range index
问题 I'm looking for ways to make a list into circular list so that I can call a number with index out of range. For example, I currently have this class: class myClass(list): definitely __init__(self, *x): super().__init__(x) which works as: >> myList = myClass(1,2,3,4,5,6,7,8,9,10) >> print(myList) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and after creating a list, I want to: >> myList[2] 3 >> myList[12] 3 >> myList[302] 3 >> myList[-1] 10 >> myList[-21] 10 ... At the moment, index [12], [302] and [-21]