Printing all the values from multiple lists at the same time

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

    To expand on top of Abhijit answer, you could use the itertools generator as the iterable within a list comprehension.

    >>> [ n for n in itertools.chain(l1, l2, l3) ]
    [1, 2, 3, 4, 5, 6, 7, 8, 9]
    

提交回复
热议问题