PEP Request: Advanced Data Structures

Steven D'Aprano steve at pearwood.info
Sun Jul 17 00:21:47 EDT 2016


On Sun, 17 Jul 2016 08:14 am, shrey.desai at gmail.com wrote:

> I have found it slightly frustrating that Python does not have built-in
> support for advanced data structures (Linked Lists, Stacks/Queues, BST) in
> its distribution.

They are hardly "advanced" data structures. They are trivial data
structures. When I did an undergraduate course in computer science, we were
expected to write them ourselves, from scratch.

Linked lists are primitive data structures used by languages that don't have
Python's advanced list data structure. For nearly everything that you think
you want a linked list, you will be better off to use a built-in list.

For stacks and queues, use collections.deque.

For binary search trees, you will mostly use a dict. If there are
exceptions, they are unusual.


> Many computer science students, developers, and software 
> engineers rely on these data structures; having the data structures be a
> part of the distribution and be maintained by the Python community would
> be immensely useful.

They really wouldn't be. I cannot imagine when anyone would want to use a
linked list when lists are available. That would be a very big step
backwards in both performance and power: harder to use, and slower.


[...]
> I'm looking to create a PEP for this issue and some people that would be
> willing to 1) vouch for this idea and 2) co-author the draft. Eventually,
> we would be co-developers for the project as well.

Perhaps I'm wrong, but it sounds to me that you should spend more time
learning Python and less time trying to mechanically translate C algorithms
into Python code. Python doesn't have a linked list class because it is
unnecessary. Python doesn't need a dedicated stack or single-threaded queue
class, because it has deque. (As a comp sci undergrad, you have probably
heard of double-ended queues.) Python already has a thread-safe queue.
*Maybe* there's a use-case for a self-balancing tree structure in Python,
but which one? How often do you need to use keys that can't be hashed? 




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list