且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从列表python的单个列表中删除子列表

更新时间:2023-02-10 14:35:54

您必须按 拆分所有子列表中的元素,然后才能使用

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)]

输出:

[['A,B,C,D', 'Y', 'hello'],
 ['A,B,C', 'Z', 'hello'],
 ['H,I,J,K,L', 'Z', 'hello'],
 ['A,D,C,B', 'Z', 'hi']]