【发布时间】:2021-01-27 09:36:36
【问题描述】:
l1= [['1', 'apple', '1', '2', '1', '0', '0', '0'], ['1',
'cherry', '1', '1', '1', '0', '0', '0']]
l2 = [['1', 'cherry', '2', '1'],
['1', 'plums', '2', '15'],
['1', 'orange', '2', '15'],
['1', 'cherry', '2', '1'],
['1', 'cherry', '2', '1']]
output = []
for i in l1:
for j in l2:
if i[1] != j[1]:
output.append(j)
break
print(output)
Expected Output:
[['1', 'plums', '2', '15'], ['1', 'orange', '2', '15']]
如何停止迭代并找到唯一元素并获取子列表? 如何停止迭代并找到唯一元素并获取子列表?
【问题讨论】:
-
你想要 l2 中没有 l1 的元素?
-
是的,只需要 l2 @Mike67
标签: python-3.x loops for-loop iteration break