python - Adding a bytearray as a key to a dictionary -
i getting error while adding bytearray key dictionary:
typeerror: unhashable type: 'bytearray'
here code:
str_dict = {} s = bytearray(10) x in range(0, 10): value = get_str(s) str_dict[s] = value
so create bytearray , function get_str(s) updates s , returns 'value'. want add both value , updated s dictionary. above error.
{[1, 2, 3]: 1} typeerror: unhashable type: 'list'
a dict key has immutable type.
list or bytearray can't use key because mutable , reason can't unique since can changed.
it seems if object __hash__
method can use key though :
i'm able use mutable object dictionary key in python. not disallowed?
Comments
Post a Comment