Terry Reedy tjreedy at
Tue Jan 20 07:08:02 CET 2015

On 1/19/2015 5:06 PM, Zachary Gilmartin wrote:
> Why aren't there trees in the python standard library?

Sequences nested withing sequences can be regarded as trees, and Python 
has these.  I regard Lisp as a tree processing languages, as it must be 
to manipulate, for example, code with nested structures.

Nested structures in general represent trees or more general graph 
forms.  The ast module uses Nodes with lists of subnodes to represent 
Abstract Syntax Trees.

Priority queues are specialized trees implemented on top of lists.  The 
heapq module is imported into 6 other modules.

Others have answered as to why other special-purpose 
constrained-structure trees have not been added to the stdlib.

It might possibly be useful to add a general Tree base class with pre-, 
in-, and post-order generators, and maybe interior and leaf node 
counters and max depth method.  Finding uses for such a thing in the 
stdlib (ast?) would be a plus in favor.

Terry Jan Reedy

More information about the Python-list mailing list