how to construct a binary-tree using python?

vdrab stijndesaeger at gmail.com
Fri May 5 23:22:33 EDT 2006


Depending on what concrete use you have for binary trees, you may want
to consider tuples. What's cool about them is that you get pattern
matching on your tree for free.

>>> x = ((2,4),(5,6))
>>> y, _ = x
>>> y
(2, 4)
>>> (_,y), _ = x
>>> y
4
>>>

Or you could code your own binary tree class subclassing tuple.
... just a thought.
v.




More information about the Python-list mailing list