This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients belopolsky, ncoghlan, pitrou, rhettinger
Date 2009-11-05.19:15:59
SpamBayes Score 2.1804225e-12
Marked as misclassified No
Message-id <1257448562.56.0.696280957518.issue7224@psf.upfronthosting.co.za>
In-reply-to
Content
The basic problem here is that the "one obvious way" to some people
(including me and Martin v. Löwis) is to use a dictionary.  Further,
there is the problem of conflating types in a user's mind -- right now,
dictionaries are all about looking up and returning values, while sets
are not.  

The current notion of sets corresponds neatly with what folks learn in
their basic math classes.  In contrast, the notion of "canonical
representatives of an equivalence class" is a more advanced mathematical
concept, one that many people are never taught.  This is even more
problematic in Python because the operation of finding canonical values
is hidden behind well designed __hash__ and __eq__ functions (for
example, it is not at all obvious how Decimal(3.0), float(3.0), and
int(3.0) all have the same hash value).  

An additional problem is the modification of set.add() so that it
violates Python's norm of having mutating methods return None.  We
should keep the language consistent in this regard.

Also, I should comment on the "appreciable memory savings".  This saves
only a single pointer (4 bytes on a 32-bit build) out of three per
string.  But the string object itself takes up memory, so the percent
savings per string is smaller than you would might expect (typically
less than 15%).

Finally, the spirit of the language moratorium is to make it so that
other Python implementations don't have to change for a few years.

FWIW, I am already going to expand the set/frozenset documention to show
some techniques for accessing and using sets.  I can add a link to a
get_equivalent() recipe that makes it possible to retrieve canonical
values from any container including sets.  That recipe uses all the
containers as-is, no patching or API changes needed.
History
Date User Action Args
2009-11-05 19:16:03rhettingersetrecipients: + rhettinger, ncoghlan, belopolsky, pitrou
2009-11-05 19:16:02rhettingersetmessageid: <1257448562.56.0.696280957518.issue7224@psf.upfronthosting.co.za>
2009-11-05 19:16:01rhettingerlinkissue7224 messages
2009-11-05 19:16:00rhettingercreate