I'm reading the Python Documentation: I don't understand how a deque is different from a list. From the documentation:
Returns a new deque object initialized left-to-right (using append()) with data from iterable. If iterable is not specified, the new deque is empty.
Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.
If a deque is basically a list, but more efficient, why would one use a list in place of a deque?
A deque is more efficient for pushing and popping from the ends. Read on, and below the list of methods you'll find:
Indexed access is O(1) at both ends but slows to O(n) in the middle. For fast random access, use lists instead.
Adding to or removing from the beginning of a list is O(n), but fetching elements from the middle is O(1). For a deque, the reverse is true.
So generally you only want a deque when you don't care about what's in the middle; you want to feed it things in some order and then get them back in that order elsewhere.