Oct-17-2020, 04:10 PM
(This post was last modified: Oct-17-2020, 04:10 PM by Gribouillis.)
buran Wrote:Same apply for e.g. listThis is not true. Random access in lists is in O(1). Of course, if you want to insert elements, that's another matter.
Again in the case of the deque, if you want to rotate often by large amounts, it will probably have worse performances than a list with a pointer to the head index.
I think it all depends on how one wants to use the structure.
Actually, you need many items to feel any difference
from collections import deque from timeit import timeit L = list(range(200000)) D = deque(L) print('list', timeit('L[100000]', 'from __main__ import L')) print('deque', timeit('D[100000]', 'from __main__ import D'))
Output:list 0.022696959997119848
deque 6.838809543995012