Sorry if a repeated question, new to programming couldn't find any appropriate answer. I am trying to convert a list to dictionary. key being x[1] and values as x[2]
Just to be clear I have a n*3 array and need to convert it to a dictionary with 2nd column as keys and 3rd column as values.
I tried:
for entry in data:
keys=entry[1]
values=entry[2]
source = dict.fromkeys(keys, values)
got error 'type list not hashable'
Went through question 4576115. However, I need to iterate through each element of a 3000+ *3 array with most elements themselves being list and thereafter setting the 2nd element of each entry as a key and the 3rd as a value. just to amplify, also tried
b = {data[i][1]: data[i][2] for i in range(0, len(data))}
and for entry in data:
keys=entry[1]
values=entry[2]
b.update(keys,values)
and
keyList.append(keys)
valueList.append(values)
b = dict(zip(keyList,valueList))
and
b={entry[1]:entry[2] for entry in data}
same issue- error 'list' not hashable
OK sorry. Got it. The issue is that the key themselves are lists. I was looking at the array and missed the element