5 ms·
Python negative indexing isn't modulo. It's just shorthand for array[len(array)-i]. >>> a = [1, 2, 3] >>> a[-1] 3 >>> a[-2] 2 >>> a[-3] 1 >>> a
by Shoop 8y ago
Python negative indexing isn't modulo. It's just shorthand for array[len(array)-i].
>>> a = [1, 2, 3]
>>> a[-1]
3
>>> a[-2]
2
>>> a[-3]
1
>>> a[-4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
- adamnemecek 8y agoThe problem is that you need to have a conditional to figure out if I is negative or not. With modulo it’s all the same.