Python Forum
If you deque a list, can it still be indexed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If you deque a list, can it still be indexed?
#6
(Nov-07-2016, 11:25 AM)wavic Wrote: Fast indexing, fast adding elements to both sides.
Those aren't the same thing. A deque is a doubly linked list allowing constant time insertion and extraction at the beginning or end. But getting an element by index is a linear time operation as you need to iterate through links to get to it.

From here https://wiki.python.org/moin/TimeComplexity:
Quote:A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still.
Reply


Messages In This Thread
RE: If you deque a list, can it still be indexed? - by Mekire - Nov-07-2016, 11:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Deque to string in Python 3 anthares 4 4,763 Jun-11-2020, 06:18 AM
Last Post: anthares
  Indexed position editing of a lst ShruthiLS 4 2,601 Sep-26-2019, 09:23 AM
Last Post: perfringo
  Operations on indexed variables in loop Fibulavie 1 1,961 Aug-14-2019, 06:07 AM
Last Post: fishhook

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020