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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -