I am trying to convert the following list:
l = ['A', 'B', 'C']
To a dictionary like:
d = {'A': 0, 'B': 1, 'C': 2}
I have tried answers from other posts but none is working for me. I have the following code for now:
d = {l[i]: i for i in range(len(l))}
Which gives me this error:
unhashable type: 'list'
list
as variable name 2. Useenumerate
as shown{j:i for i,j in enumerate(l)}
list
are probably lists, although you could have made other mistakes, like writinglist: i
instead oflist[i]: i
.