Printing all the values from multiple lists at the same time

后端 未结 7 1885
遥遥无期
遥遥无期 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:53

    It you're lists are not all the same length it is often better to use map:

    >>> l1 = [1, 2, 3]
    >>> l2 = [4, 5, 6]
    >>> l3 = [7, 8, 9, 2]
    >>> for x, y, z in map( None, l1, l2, l3):
    ...     print x, y, z
    ...
    1 4 7
    2 5 8
    3 6 9
    None None 2
    

提交回复
热议问题