我已经阅读了关于删除列表中子列表的Stack Overflow帖子Removing sublists from a list of lists,但是在将其扩展到我的数据集时,它并没有起作用。因此,我发布了一个新问题。
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']]
我想移除一些元素,并将期望的输出贴在下面:
**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']]
我已经尝试了以下代码:
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)]