Why are tuples immutable?

Fredrik Lundh fredrik at pythonware.com
Thu Dec 16 06:15:39 EST 2004


Antoon Pardon wrote:

> That depends on whether the programmes wants value equality
> or identity equality.
>
> In the first case the programmer shouldn't mutate a after
> it was introduced as key in the dictionary; but should
> either introduce a copy or work on a copy later. As
> such your snippet of code would become.
>
>  a = [1,2,3]
>  d[a[:]] = 9
>  a.append(4)
>  print d[a]
>
> And this would raise a KeyError, unless the list [1,2,3,4]
> would be in the dictionary.
>
> In the second case your code would produce 9.

how does the dictionary know if you want key value equality or key
identity equality?

</F> 






More information about the Python-list mailing list