Printing all the values from multiple lists at the same time

后端 未结 7 1884
遥遥无期
遥遥无期 2020-12-19 05:02

Suppose I have 3 lists such as these

l1 = [1,2,3]
l2 = [4,5,6]
l3 = [7,8,9]

how do I get to print out everything from these lists at the s

相关标签:
7条回答
  • 2020-12-19 05:59

    If you mean that you have 3 lists of equal length and you want to print out their contents as 3 columns, then how about zip() to connect the columns and a list comprehension to print() on each iteration:

    [ print(row) for row in zip(l1, l2, l3) ]
    

    The above will print repr's of tuple(s). If you want to format the values otherwise:

    [ print("{} / {} / {}".format(*row)) for row in zip(l1, l2, l3) ]
    

    Nobody said you have to use the output of a list comprehension.

    0 讨论(0)
提交回复
热议问题