[Python-Dev] Getting values stored inside sets (original) (raw)

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Apr 3 19:16:24 CEST 2009


I just want to add a link to a 2.5 year old discussion on this issue: <http://bugs.python.org/issue1507011>. In that discussion I disagreed with Martin and argued that "interning is a set operation and it is unfortunate that set API does not support it directly."

On Fri, Apr 3, 2009 at 12:43 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:

I've stumbled upon an oddity using sets.  It's trivial to test if a value is in the set, but it appears to be impossible to retrieve a stored value, other than by iterating over the whole set. Of course it is. That's why it is called a set: it's an unordered collection of objects, keyed by nothing. If you have a set of elements, and you check "'foo' in s", then you should be able just to use the string 'foo' itself for whatever you want to do with it - you have essentially created a set of strings. If you think that 'foo' and Element('foo') are different things, you should not implement eq in a way that they are considered equal. Regards, Martin


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/alexander.belopolsky%40gmail.com



More information about the Python-Dev mailing list