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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -