+ 4

Why can't we use list as dictionary key in Python?

I had this question for some while in my mind while writing a code. Can anyone explain as to why and whether we can use list as dictionary keys?

20th Dec 2017, 7:24 AM
Tamoghna Saha
2 Antworten
+ 8
good question! keys must be immutable. It is for your own safety. Otherwise you could accidently destroy the dic.
20th Dec 2017, 8:26 AM
Oma Falk
Oma Falk - avatar
+ 6
Because you are able to change list items and tuples not.
20th Dec 2017, 7:31 AM
Vukan
Vukan - avatar