pc_pyr :
I have gone through Removing sublists from a list of lists, but it didn't work for my case when I extend it for my dataset. Hence posting a new question.
list1=[['A,C,D', 'Y', 'hello'],
['A,B,D', 'Y', 'hello'],
['B,C,D', 'Y', 'hello'],
['A,B,C,D', 'Y', 'hello'],
['A', 'Z', 'hello'],
['A,C', 'Z', 'hello'],
['B,C', 'Z', 'hello'],
['A,C', 'Z', 'hello'],
['A,B,C', 'Z', 'hello'],
['H,I,J,K', 'Z', 'hello'],
['H,K', 'Z', 'hello'],
['H,L', 'Z', 'hello'],
['I,J,K,L', 'Z', 'hello'],
['H,I,J,K,L', 'Z', 'hello'],
['B,C,D','Z','hi'],
['A,D,C,B','Z','hi']]
I want to remove few elements and posting the desired output below:
**Output**
[['A,B,C,D', 'Y', 'hello'],
['A,B,C', 'Z', 'hello'],
['H,I,J,K,L', 'Z', 'hello'],
['A,D,C,B','Z','hi']]
I have tried with the code below:
sets = [set(l) for l in lists]
new_list = [l for l,s in zip(lists, sets) if not any(s < other for other in sets)]
kederrac :
you have to split all by ,
al the elements from your sublists than you can use the solution you already have found:
st = [{i for e in l for i in e.split(',') } for l in list1]
[l for l, s in zip(list1, st) if not any(s < other for other in st)]
output:
[['A,B,C,D', 'Y', 'hello'],
['A,B,C', 'Z', 'hello'],
['H,I,J,K,L', 'Z', 'hello'],
['A,D,C,B', 'Z', 'hi']]