Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61754

Re: Tree library - multiple children

Date 2013-12-12 14:13 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Tree library - multiple children
References <52A9FD0A.9080804@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4023.1386882850.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/12/2013 11:14 AM, Ricardo Aráoz wrote:
> I need to use a tree structure. Is there a good and known library?
> Doesn't have to be binary tree, I need to have multiple children per node.

There are lots of types of tree structures that may or may not be
applicable to your problem.  And it depends on what kind of data you're
storing.  For example, I wrote a parser years ago (in C) that processed
BER-encoded structured data (sort of like binary xml).  Turned out that
the nested structure of BER-encoded data lends itself well to
"left-child, right-sibling" trees (and it happens to be binary, which
makes for easy traversal).

In any even Python's data primitives are powerful enough that you don't
need a library at all.  Just use Python's built-in primitives.  You can
do most tree structures with just list manipulation, without any class
overhead at all.

In fact in my case, my "left-child right sibling" trees are by
definition lists (think LISP car and cdr) or tuples.  The LISP-esque
nature of Python's data types always did make Python appeal to me.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Tree library - multiple children Michael Torrie <torriem@gmail.com> - 2013-12-12 14:13 -0700

csiph-web