python match lists
Question: Removing supersets when sublists are compared with other sublists in a
list_of_lists

Input:

    
    
      my_list = [['cat','bat'],['sat','rat','mat'],['cat','bat','hat'],['pat','mat']]
    

Here ['cat', 'bat'] is a subset of ['cat', 'bat', 'hat'] So I need to remove
the superset ['cat', 'bat', 'hat'] from my_list

Desired Output should be:

    
    
      my_new_list = [['cat','bat'],['sat','rat','mat'],['pat','mat']]
    

I found a similar thread but could not implement the same code for comparing
sublists with one another. Can anyone help me with this?

    
    
      def match(my_list[],my_list[]):
           matches = set(my_list[]).issuperset()
           return [remove(my_list[]) for sublist in my_list if matches (sublist)]
    


Answer: Take a look at this:

    
    
    from itertools import permutations
    
    my_list = [['cat','bat'],['sat','rat','mat'],['cat','bat','hat'],['pat','mat']]
    
    for a,b in permutations(my_list,2):
        if set(a).issubset(b):
            my_list.remove(b)
    print my_list
    

