I have already checked some question-answers related to Unhashable type : 'list' in stackoverflow, but none of them helped me. Here is my partial code:
keyvalue = {};
input_list_new = input_list;
for file in os.listdir('Directory/'):
pathname = os.path.join('Directory/', file)
dict_table = []; # creates blank 2d array
with open(pathname) as dict_file:
for line in dict_file:
dict_table.append(line.strip().split("\t"))
dict_list = [];
for i in list(range(0, len(dict_table))):
dict_list.append(dict_table[i][0])
matched = list(set(dict_list) & set(input_list))
for i in list(range(0, len(matched))):
temp = [dict_table[0][0]] + dict_table[(dict_list.index(matched[i]))]
input_list_new.insert((input_list_new.index(matched[i])), temp)
dict = {matched[i] : temp}
keyvalue.update(dict)
where dict_table is a list of lists, dict_list is just a list & keyvalue is a python dictionary. The entire code runs well when ever I comment the line input_list_new.insert((input_list_new.index(matched[i])), temp), but without that line being commented, it shows Unhashable type : 'list' error.
dictas a variable name as that shadows the built-indicttype, which can lead to mysterious bugs if you attempt to create a dictionary usingdict(). That's not a problem for the partial code you've posted, but it may affect subsequent code in that function / module.matched[i]on its on line, putinput...()on its own, etc{}[[1,2]].