Python 布尔变量组合-无重复
例如,我试图让python给我一组名称的组合,这些名称可以是负的,也可以是正的Python 布尔变量组合-无重复,python,Python,例如,我试图让python给我一组名称的组合,这些名称可以是负的,也可以是正的 [['A+','A-'],['B+','B-']] -> [['A+','B+'],['A+','B-'],['A-','B+'],['A-','B-']] 我想不出一种使用itertools来实现这一点的方法。您可以使用以下方法来实现: from itertools import product a = [['A+','A-'],['B+','B-']] print list(product(*a))
[['A+','A-'],['B+','B-']] -> [['A+','B+'],['A+','B-'],['A-','B+'],['A-','B-']]
我想不出一种使用itertools来实现这一点的方法。您可以使用以下方法来实现:
from itertools import product
a = [['A+','A-'],['B+','B-']]
print list(product(*a))
[OUTPUT]
[('A+', 'B+'), ('A+', 'B-'), ('A-', 'B+'), ('A-', 'B-')]
您可以使用以下方法执行此操作:
from itertools import product
a = [['A+','A-'],['B+','B-']]
print list(product(*a))
[OUTPUT]
[('A+', 'B+'), ('A+', 'B-'), ('A-', 'B+'), ('A-', 'B-')]
您可以使用以下方法执行此操作:
from itertools import product
a = [['A+','A-'],['B+','B-']]
print list(product(*a))
[OUTPUT]
[('A+', 'B+'), ('A+', 'B-'), ('A-', 'B+'), ('A-', 'B-')]
您可以使用以下方法执行此操作:
from itertools import product
a = [['A+','A-'],['B+','B-']]
print list(product(*a))
[OUTPUT]
[('A+', 'B+'), ('A+', 'B-'), ('A-', 'B+'), ('A-', 'B-')]
只需分别迭代[0]和[1]
outputList = []
for a in inputList[0]:
for b in inputList[1]:
outputList.append([a,b])
只需分别迭代[0]和[1]
outputList = []
for a in inputList[0]:
for b in inputList[1]:
outputList.append([a,b])
只需分别迭代[0]和[1]
outputList = []
for a in inputList[0]:
for b in inputList[1]:
outputList.append([a,b])
只需分别迭代[0]和[1]
outputList = []
for a in inputList[0]:
for b in inputList[1]:
outputList.append([a,b])