两个for循环嵌套,写成一个列表生成式

将两个嵌套for循环写成一个列表生成式
如,有一个嵌套列表,a=[[1,2],[3,4],[5,6]],要提取列表里的每一个元素

用for循环处理:

for i in a:
    for j in i:
        print(j)

用列表生成式:

b = [j for i in a for j in i]

 

 

原文地址:https://www.cnblogs.com/GumpYan/p/12603116.html