Terry Reedy wrote: >> In this model, a >> get() method, or even a __getitem__ with s[k] is k, is only natural. > > No, if key and value were the same thing, the get method would be > nonesense, as Guido said. But since they are not, since the implict key > is an abstract class, retrieving the representative, perhaps canonical > object given *any* member *is* natural. Being able to do so is also a > standard practice in mathematics.
To formalise this invariant to some degree: given a set "s" and two items "k1" and "k2", such that "k1 in s" and "k2 in s" and "k1 == k2", there is a single item "k" in s such that "k1 == k" and "k2 == k". If __getitem__ were to be provided by sets, then the last part of that invariant could be written "s[k1] is s[k2]". If you actually care about that aspect of the semantics for a particular application, it would be far clearer to use a full dict() and live with the additional memory usage. While I can see how saving that pointer-per-entry might make sense in some circumstances, for most I would see it as a needlessly confusing micro-optimisation. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com