擅长:python、mysql、java
<p>您可以这样使用来自<code>itertools</code>的<code>product</code>方法,以便获得所需的输出:</p>
<pre><code>from itertools import product
a = ("up1","up2","up3")
# assuming your b variable is like this one
b = ("down1", "down2","down3")
c = ["".join(k) for k in list(product(a,b))]
subfinal = list(product(c,c))
# removing the duplicates
# maybe not the best way to do it...
# also removing those kind of data: up1down1,up1down2
# also removing those kind of data: up1down1,up3down1
final = [k for k in subfinal if k[0] != k[1] and k[0][:3] != k[1][:3] and k[0][3:] != k[1][3:]]
print('total: ', len(final))
for k in final:
print(", ".join(k))
</code></pre>
<p>输出:</p>
<pre><code>total: 36
up1down1, up2down2
up1down1, up2down3
up1down1, up3down2
up1down1, up3down3
up1down2, up2down1
up1down2, up2down3
up1down2, up3down1
up1down2, up3down3
...
</code></pre>