set partition question

"Martin v. Löwis" martin at v.loewis.de
Sun May 25 23:28:33 EDT 2008


> There may be arbitrarily many set elements (denoted by integers
> 1,2,3,...), arbitrarily many combinations of the elements composing
> the sets s_i (s0, s1, ...). We can use any of python's set operations
> or combination of those operations.

That still allows for trivial solutions:

Given s0, and s1..sn, the following Python code outputs a Python
fragment that, when run, returns s0:

print "set()",
for e in s0:
    print ".union(set([%s]))" % repr(e),

For s0=set([1,2,3]), I get

set() .union(set([1])) .union(set([2])) .union(set([3]))

Or, more trivially,

print repr(s0)

which gives me

set([1,2,3])

In either case, s0 is generated through "any of python's set
operations".

Regards,
Martin



More information about the Python-list mailing list