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

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


lst = [1, 2, 3, 4, 5]

def maketup(lst):
    cur_item = lst[-1]
    lst = lst[:-1]
    if len(lst):
        return maketup(lst), cur_item
    else:
        return cur_item

print maketup(lst)

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

But I'm confused as to what you mean by :
> Among them, I want to pair up terminals until there is only one left
> at the end.

One what? one pair?, one terminal meaning one number?



More information about the Python-list mailing list