Python - Dictionaries and keys | SoloLearn: Learn to code for FREE!


Python - Dictionaries and keys

Why in a dictionary, key has to be an immutable?

6/30/2020 2:04:51 AM

Paolo De Nictolis

3 Answers

New Answer


Because if a key is mutable its value could change. Thanks for your question and happy coding.


Paolo De Nictolis Official Answer by Python 👇


python hashes the dictionary keys for sorting purposes. if you could change the keys the hashing algorithm could clash. i believe you can make lists of lists if you wanted to in python to get around this, but that would make working with your data slower. and theres more complex ways to get around it listed in the answers above.