Idiom for flattening a shallow nested list: how does it work?

前端 未结 4 962
闹比i
闹比i 2021-01-05 10:57

I found this bit of code in a module I am working on:

l = opaque_function()
thingys = [x for y in l for x in y]

I can\'t read this. By expe

4条回答
  •  太阳男子
    2021-01-05 12:00

    lis=[x for y in l for x in y] is Equivalent to:
    
    
    lis=[]
    for y in l:
       for x in y:
          lis.append(x)
    

提交回复
热议问题