How to populate all possible hierarchical clusterings from a set of elements?

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Thu Jan 13 05:27:20 EST 2011


DevPlayer <devplayer at gmail.com> writes:

> def maketup(lst):
>
>     if len(lst) == 1:
>         return lst[0]
>
>     elif len(lst) == 2:
>         return (lst[0],lst[1])
>
>     elif len(lst) > 2:
>         return ( (maketup(lst[:-2]), lst[-2]), lst[-1])

The OP wants all binary trees over the elements, not just one.

-- Alain.



More information about the Python-list mailing list