Making a tree out of a 2 column list

Jorgen Grahn grahn+nntp at snipabacken.dyndns.org
Thu Apr 19 22:38:38 CEST 2007


On Sat, 14 Apr 2007 11:37:11 -0300, Sebastian Bassi <sbassi at clubdelarazon.org> wrote:
> I have a two column list like:
>
> 2,131
> 6,335
> 7,6
> 8,9
> 10,131
> 131,99
> 5,10
>
> And I want to store it in a tree-like structure.

CS side note: your "columns" describe a graph;
http://en.wikipedia.org/wiki/Graph_(mathematics)

> So if I request 131, it should return all the child of 131, like 2, 10
> and 5 (since 5 is child of 10).

OK, so it is a directed graph.

You might want to think about whether it is also a DAG. If not, you
could be asked for the children of 1 in
2, 1
1, 2

As I interpret your specification, the correct answer is [1, 2] -- the
set of children for 1.

/Jorgen

-- 
  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.dyndns.org>  R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list