python-3.x - python : iterate over a nested list and a flat list together

标签 python-3.x list

我正在尝试一起迭代两个列表(嵌套列表和平面列表):

例如:

x_list = ['11', '22']
y_list = [[33, 44], [55, 66, 77]]


for x, y in zip(x_list, y_list):
    print(x,y)

输出:

11 [33, 44]
22 [55, 66, 77]

但我想输出如下:

11 33

11 44​​

22 55

22 66

22 77

最佳答案

您可以在嵌套循环中迭代 y 中的项目:

for x, y in zip(x_list, y_list):
    for i in y:
        print(x, i)

关于python-3.x - python : iterate over a nested list and a flat list together,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62307842/

相关文章:

python - 如何从定界字符串中剥离值

python-3.x - Google Cloud Functions Python 日志记录问题

Python:打印为每个键分配多个值的字典元素

C++ 用 ostream 以外的东西重载运算符 <<

list - 用于验证括号匹配的 Haskell 函数

python-3.x - 如何检测不同的颜色

python - 多彩输入Python

html - 在 Selenium 中自动执行下拉菜单而不选择

jquery - 使用父元素的属性设置 img src 的值

list - 将元素添加到列表末尾的正确方法?