// Thomas Dybdahl Ahle (https://github.com/thomasahle)// Source: http://compprog.wordpress.com/2007/10/15/generating-the-partitions-of-a-setif not set_:
yield ()
returnfor i in xrange(2**len(set_) / 2):
parts = [set(), set()]for item in set_:
parts[i&1].add(item)
i >>= 1for b in partitions(parts[1]):
After Change
// Convert the partition into a sorted tuple of sorted tuples.// Sort by smallest parts first, then lexicographically.
partition = tuple(sorted(partition, cmp=len_cmp))
yield partition