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

DevPlayer devplayer at gmail.com
Thu Jan 13 05:29:32 EST 2011


tuple([ (tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else
lst[x-1]) for x in lst[::2]])

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


# or
x = ((tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else
lst[x-1]) for x in lst[::2])
x.next()
(1, 2)
x.next()
(3, 4)
x.next()
5



More information about the Python-list mailing list