On Apr 29, 2020, at 08:33, Christopher Barker <python...@gmail.com> wrote:
> 
> I've wondered about Linked Lists for a while, but while there are many 
> versions on PyPi, I can't find one that seems to be mature and maintained. 
> Which seems to indicate that there isn't much demand for them.

I think there’s lots of demand for them, but there are so many different 
variants that can’t substitute for each other (try taking any nontrivial sample 
code using Haskell’s single-linked, no-handle, immutable tail-sharing list and 
rewriting it with C++’s doubly-linked handled mutable list, or vice-versa), and 
most of the key operations fit so poorly with Python’s sequence/iterable API, 
and they’re all so easy to build, that people just build the one they need 
whenever they need it.

I do have a few different linked lists in my toolbox that have come up often 
enough that I stashed them (an immutable cons, a handled double-linked list, a 
cffi wrapper for a common style of C internally-linked lists, probably others), 
but half the time I reach for one I have to modify it anyway, so I haven’t 
bothered to turn them into a package I just import and use.

And, while I did add the whole (Mutable)Sequence API to each one (because it’s 
convenient for debugging and REPL exploration to be able to list(xs), or to get 
a repr that’s written in terms of a from_iter classmethod so I can eval it 
back, etc.), I usually don’t use that API for anything but debugging. When 
you’re dealing with linked lists, you usually need to deal with the nodes 
directly. For example, one big reason to use linked lists is constant-time 
splicing, but you can’t splice in constant time if all you have is the 
head/handle and/or an opaque iterator that only knows how to go forward; you 
need the node before the splice point (or, for doubly-linked, after is fine 
too). Another reason to use (Lisp/Haskell-style) linked lists is that they 
automatically release nodes as you iterate unless you keep a reference to the 
head, but that’s clumsy to do with Python-style APIs. And so on.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DGBRHXGXHAMERZRQW2WN5XMU22WBIHUK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to