Remove duplicates from nested list using list as keys
Question: 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']] 
    


Answer: Lists cannot be used as keys in dictionaries as they are _mutable_ , they can
be changed, so they can't be hashed. Well, they _could_ be hashed, but _that
hash might change_. As a dictionary relies on hashing its keys to be
efficient, hashes must stay constant. The solution, then, is to use a
**tuple** , which is exactly like a list except that it's immutable. To
convert a list `L` to a tuple, simply do `tuple(L)`.

