打印数组的值[重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

以此为例

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或递归函数来编写它,但我无法处理它真的让我疯狂

期待一些帮助:(

python
1个回答
0
投票
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)
© www.soinside.com 2019 - 2024. All rights reserved.