Provided is a singly-linked linked list module (not to be confused with Python's builtin list type). Also provided are LIFO (stack) and FIFO (queue) implementations.

All 3 modules are thoroughly unit tested; pass pylint; and run on CPython 2.7, CPython 3.6, Pypy 5.10.0, Pypy3 5.10.0 and Jython 2.7.

Linked_list allows:

You can obtain the code here.

Interestingly, I modified count to use this class instead of a builtin Python list, and it was both slower and used more RSS (memory). I suppose there's a reason why people don't use linked lists in Python.

Also, collections.deque makes the LIFO and FIFO less interesting.

But at least all this was fun to write . Also on the plus side, these are better abstracted - that is, they fit some specific purposes well and don't allow things that may be best avoided.

Example use:

See also this list of datastructures I've worked on.

Hits: 188455
Timestamp: 2024-02-29 10:21:22 PST

Back to Dan's tech tidbits

You can e-mail the author with questions or comments: