1

I need something like

list_dict_dict = {
    [] : {}
}

the problem is [] isnt hashable and cannot be used as a dictionary key

any data structure out there i can used to map a list to a dict?

ealeon
  • 11,288
  • 20
  • 84
  • 159

1 Answers1

8

Convert the list to a tuple

my_dict = {}
my_tuple = tuple(my_list)
my_dict[my_tuple] = my_value

However, afterwards if you make any changes in the list, those will not be reflected in the tuple that you used as the key. List cannot be used as a dict key because it can be mutated, which will change its hash each time an object is added or removed.

Abhinav Upadhyay
  • 2,408
  • 20
  • 32