这个问题在这里已有答案:
以此为例
x = [1, 2];
y = [3, 4];
z = [5, 6];
tp = (x, y, z)
print_tpl(tuple)
实际上我想用这种方式打印tp中的数组值
135 136 145 146 235 236 245 246
考虑到tp本身可能有3个以上的变量,你能帮我写“print_tpl”函数吗?它可能是(x,y)或(x,y,z,n,m)
我尝试通过嵌套for或递归函数来编写它,但我无法处理它真的让我疯狂
期待一些帮助:(
import itertools
def print_tpl(tp):
print (list(itertools.product(*tp)))
x = [1, 2]
y = [3, 4]
z = [5, 6]
tp = (x, y, z)
print_tpl(tp)