j
我的目标是将下面列表中的项目的交集 (和)捕获k
到三个单独的列表中。
j=[[1,2,3],[2,3,4,],[2,1,3]]
k=[[2,4,5],[3,2,1,][4,5,6]]
我的尝试:
>>> b=[]
>>> for x in j:
for y in k:
c=[h for h in x if h in y]
b.append(c)
输出:
>>> b
[[2], [1, 2, 3], [], [2, 4], [2, 3], [4], [2], [2, 1, 3], []]
期望的输出:
[[[2], [1, 2, 3], []], [[2, 4], [2, 3], [4]], [[2], [2, 1, 3], []]]