按顺序合并几个列表

时间:2018-06-27 23:37:29

标签: python python-3.x list

我列出了三个清单。有不同的顺序。

list1 = ['frame1', 'frame3', 'frame5', 'frame7']
list2 = ['.102', '.103', '.104', '.105']
list3 = ['.ext', '.ext', '.ext', '.ext']

如何将这三个列表结合起来才有意义?

frame1,.102,.ext

当我做print(list1 + list2 + list3)时,输出当然是:

frame1,frame3,frame5,frame7,.102,.103,.ext,.ext

我需要我的输出像我上面说的那样,frame1,.102,.ext

1 个答案:

答案 0 :(得分:0)

使用zip将每个列表中具有相同索引的项目组合在一起:

for x, y, z in zip(list1, list2, list3):
    print(x, y, z)

subject1 subject2 subject3
subject4 subject5 subject6
subject7 subject8 subject9
subject10 subject11 subject12