Python 多准则结合

Python 多准则结合,python,python-3.x,conditional-statements,combinations,Python,Python 3.x,Conditional Statements,Combinations,我有以下三个长度不等的列表: a = [2.13, 5.48,-0.58] b = [4.17, 1.12, 2.13, 3.48,-1.01,-1.17] c = [6.73, 8, 12] d = [(2.13,2.13),(5.48,-1.17),(-0.58,4.17)] e = [(4.17,12),(2.13,6.73)] 我需要为a中的x创建一个组合_abc=[(x,y,z) b中的y 对于c]中的z,如果(x,y)不等于d,(y,z)不等于e如果我理解您的意思正确,只需

我有以下三个长度不等的列表:

a = [2.13, 5.48,-0.58]

b = [4.17, 1.12, 2.13, 3.48,-1.01,-1.17]

c = [6.73, 8, 12]

d = [(2.13,2.13),(5.48,-1.17),(-0.58,4.17)]

e = [(4.17,12),(2.13,6.73)]
我需要为a中的x创建一个组合_abc=[(x,y,z) b中的y
对于c]中的z,如果(x,y)不等于d,(y,z)不等于e如果我理解您的意思正确,只需将If语句添加到您的理解列表中:

[(x, y, z) for x in a for y in b for z in c if (x, y) not in d and (y, z) not in e]
为了简单起见,您还可以使用
itertools.product

from itertools import product

[(x, y, z) for x, y, z in product(a, b, c) if (x, y) not in d and (y, z) not in e]

如果我理解正确,只需将If语句添加到您的理解列表中:

[(x, y, z) for x in a for y in b for z in c if (x, y) not in d and (y, z) not in e]
为了简单起见,您还可以使用
itertools.product

from itertools import product

[(x, y, z) for x, y, z in product(a, b, c) if (x, y) not in d and (y, z) not in e]

(x,y)不等于d
的情况下,你的意思是
d
不包含
(x,y)
?作为一个侧面,你的理解可能更容易理解为
itertools.product(a,b,c)
,而不是为
子句显式地嵌套三个
不等于d
您的意思是
d
不包含
(x,y)
?作为一个侧面,您的理解可能更容易理解为
itertools.product(a,b,c)
,而不是用三个
子句进行显式嵌套。