[Python] The two basic nested loop for a written list formula

The two nested loop for a written list of Formula
e.g., a nested list, a = [[1,2], [3,4], [5,6]],

To extract every element of the list

Loop processing for:

for i in a:

    for j in i:

        print(j)

 

Formula list by:

 

b=[j for i in a for j in i]   #注意两个for的顺序

    print(b)

 

>>> b

[1, 2, 3, 4, 5, 6]

 

Published 354 original articles · won praise 163 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_41856814/article/details/103405672