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

DevPlayer devplayer at gmail.com
Thu Jan 13 04:51:02 EST 2011


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])

maketup(lst)

((((1, 2), 3), 4), 5)




More information about the Python-list mailing list