22
votes

I know in c++ it already exist #include <list> Now I am curious to know if it exist in python also.

2
Welcome to SO! Could you elaborate why you need this? Python already has the list type.georg
A Python list is equivalent to an array, not a linked list, it's a different data type.Leigh
Why on earth was this closed? It is a short, self-contained question with a cross language example.Charles Merriam

2 Answers

16
votes

You can also take a look at llist python package, which provides some useful features that deque does not. There are not only doubly linked lists, but also single linked lists data structure in that package. IMHO, one of the biggest advantages of this package is the ability to store a reference to the llist elements.

1
votes

It appears that collections.deque is a doubly-linked-list library in Python. According to the documentation, it should have approximately O(1) cost when appending or popping from the head or the tail, as well as O(n) for regular inserts (which matches what we'd expect from a linked list).

API: http://docs.python.org/2/library/collections.html#collections.deque

Source: https://stackoverflow.com/a/282238/2441252