I use to have two lists, files and g_list which were both regular lists. I wanted to remove the duplicates from files and have g_list match. I found this solution;
from collections import OrderedDict as odict
od = odict.fromkeys(zip(files, g_list))
files, g_list = zip(*od)
I have since modified g_list to be a nested list, but now when I run the above code I get this TypeError:
File "/usr/lib/python2.7/collections.py", line 199, in fromkeys
self[key] = value
File "/usr/lib/python2.7/collections.py", line 58, in __setitem__
if key not in self:
TypeError: unhashable type: 'list'
How do I remedy this? Or is there another way to do what I desire?
Edit:
Input:
files = ['red', 'green', 'blue', 'green', 'yellow']
g_list = [['x','y'], ['z'], ['q','r','x'], ['z'], ['x', 'r']]
Desired Output:
files = ['red', 'green', 'blue', 'yellow']
g_list = [['x','y'], ['z'], ['q','r','x'], ['x', 'r']]
tupleinstead. Can be as simple astuple(my_list)len(files)before and after yields the same result.filesandg_list, and what you want to have afterwards?set(my_tuple)to remove the duplicates