Is it possible to hash lists
?
For example, I know that hashes of tuples are possible:
>>> hash((1,2,3,4,5,6))
-319527650
But is it possible to hash a list
?
>>> hash([1,2,3,4,5,6])
hash_value
Possible Solution:
Is it possible to hash lists
?
For example, I know that hashes of tuples are possible:
>>> hash((1,2,3,4,5,6))
-319527650
But is it possible to hash a list
?
>>> hash([1,2,3,4,5,6])
hash_value
Possible Solution:
If you really need to use a list as a dictionary key, try converting it to a string first.
my_list = str(my_list)
Python doesn't allow you to use mutable data as keys in dictionaries, because changes after insertion would make the object un-findable. You can use tuples as keys.
Just try it:
So you can get
hash
oftuple
andfrozenset
since the are immutable, and you can't do it forlist
andset
because they are mutable.