exercise: partition a list by equivalence

John Machin sjmachin at lexicon.net
Sun Feb 20 05:29:33 EST 2005


Xah Lee wrote:
> 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?

http://www.python.org/doc/2.3/whatsnew/
http://www.python.org/doc/2.4/whatsnew/whatsnew24.html

You must be running 2.3. If you persist in running 2.3, put the
following at the top of the file:

import sys
PY_VERSION = sys.version_info[:2]
if PY_VERSION == (2,3):
    from sets import Set as set
    from sets import ImmutableSet as frozenset

That will get Reinhold's gadget working under 2.3. The bearophile's
function uses collections.deque which is built-in to 2.4.

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

Look at the newsgroup again. By my count there are apparently-working
versions from SIX people: Reinhold, bear.+, Brian Beck, David Eppstein,
yourself, and me. Only David's uses stuff that's not in the Python 2.4
off-the-shelf distribution.




More information about the Python-list mailing list