[perl-python] exercise: partition a list by equivalence

Xah Lee xah at xahlee.org
Sun Feb 20 04:15:25 EST 2005


when i try to run the following program, Python complains about some
global name frozenset is not defined. Is set some new facility in
Python 2.4?

©# from Reinhold Birkenfeld
©def merge(pairings):
©    sets = {}
©    for x1, x2 in pairings:
©        newset = (sets.get(x1, frozenset([x1]))
©                  | sets.get(x2, frozenset([x2])))
©        for i in newset:
©            sets[i] = newset
©
©    return [list(aset) for aset in set(sets.itervalues())]

it would be nice if the two working programs do not use some package.
This problem shouldn't need to.

 Xah
 xah at xahlee.org
 http://xahlee.org/PageTwo_dir/more.html




More information about the Python-list mailing list