Why no list as dict key?

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Apr 20 19:06:31 EDT 2022


On 21/04/22 6:22 am, Abdur-Rahmaan Janhangeer wrote:
> Using Python3.9, i cannot assign a list [1, 2] as key
> to a dictionary. Why is that so?

If the contents of the list were to change after using it as
a key, its hash value would no longer match its position in
the dict, so subsequent lookups could fail to find it.

-- 
Greg


More information about the Python-list mailing list