If I were a programmer writing this functionality, I would implement it as negative means start from right, positive means start from left, which will result in q[-1] much faster than q[9999].
However, as -1 transformed to 1 step from right seems no more time consuming than transform 9999 to 1 step from right, so why does q[-1] is slower than q[9999]?
Thanks
>>> q = collections.deque()
>>> q.extend(range(10000))
>>> %timeit q[-1]
50.7 ns ± 0.195 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
>>> %timeit q[9999]
40.5 ns ± 0.528 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)