我要打印的内容如下,为简单起见,在每个字符串中使用 2 个变量。我认为使用循环有问题,我对 Python 有点陌生。提前致谢!
com0 <-(a) with (1,)
com1 <-(a) with (2,)
com2 <-(a) with (1, 2)
com3 <-(b) with (1,)
com4 <-(b) with (2,)
com5 <-(b) with (1, 2)
com6 <-(a,b) with (1,)
com7 <-(a,b) with (2,)
com8 <-(a,b) with (1, 2)
这是我试过的:
import itertools
i = 0 #v1
j = 0 #v2
v1 = [1, 2]
v2 = ["a","b"]
while j < 2**len(v2):
for K in range(0, len(v2)+1):
while i < 2**len(v1):
for L in range(0, len(v1)+1):
for subset2 in itertools.combinations(v1, L):
for subset1 in itertools.combinations(v2, K):
print("com{0} <-{1} with {2}".format(i,subset1,subset2))
i+=1
j+=1
牧羊人nacy
杨魅力
相关分类