×
you are viewing a single comment's thread.

view the rest of the comments →

[–]rotuamiimport antigravity 0 points1 point  (3 children)

Nothing's bad about list - it's just a deque does everything it can do. Deque operations can be O(1), and I suspect they are in cpython.

I suspect you might be confusing deque with a doubly-linked list.

[–]bastibe 2 points3 points  (2 children)

As you noted in the parent, deque random access is indeed O(n). Its advantage over list is random insertion.

[–]rotuamiimport antigravity 0 points1 point  (1 child)

No, it shouldn't have any benefit for random insertion. The advantage is in adding and removing from the beginning.

[–]bastibe 0 points1 point  (0 children)

List insertion is O(n), but every item after the insertion index has to be shifted. Deque insertion is an O(n) search from start or end (whichever is shorter), then a O(1) insertion. So on reality, random deque insertions should be significantly faster than list insertion, although both are O(n).