[Python-ideas] Why can't you put mutable values in a set? (was: Fwd: Why do equality tests between OrderedDict keys/values views behave not as expected?)

Guido van Rossum guido at python.org
Sat Dec 19 20:01:14 EST 2015


Hah, I never have time to blog any more. :-(

However you can just link to the mailman archives if you want to reference
it.

On Sat, Dec 19, 2015 at 12:16 AM, Ben Finney <ben+python at benfinney.id.au>
wrote:

> Guido van Rossum <guido at python.org> writes:
>
> > The link between hashing and immutability is because objects whose
> > hash would change are common, e.g. lists, and using them as dict keys
> > would be very hard to debug for users most likely to make this
> > mistake. […]
> >
> > […] But the real question here isn't "why aren't all things hashable"
> > but "why can't you put mutable values into a set". […]
> >
> > Hashing comes into play because all of Python's common data structures
> > use hashing to optimize lookup -- but if we used a different data
> > structure, e.g. something based on sorting the keys, we'd still have
> > the mutability problem. And we'd have worse problems, because values
> > would have to be sortable, which is a stricter condition than being
> > immutable.
> >
> > In any case, you can't solve this problem by making all values hashable.
>
> That was a great explanation; you answered several points on which I was
> vague, and you addressed some things I didn't even know were problems.
>
> I'd love to see that edited to a blog post we can reference in a single
> article, if you have the time.
>
> --
>  \         “I went to the museum where they had all the heads and arms |
>   `\      from the statues that are in all the other museums.” —Steven |
> _o__)                                                           Wright |
> Ben Finney
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/




-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151219/22aa46c9/attachment.html>


More information about the Python-ideas mailing list