I am able to get it to work but I don't understand how it works
li=[[0,1,2],[3,4,5],[6,7,8]]
li2 = [ y for x in li for y in x]
output: li2: [0,1,2,3,4,5,6,7,8]
I am able to get it to work but I don't understand how it works
li=[[0,1,2],[3,4,5],[6,7,8]]
li2 = [ y for x in li for y in x]
output: li2: [0,1,2,3,4,5,6,7,8]
Second line can be written as:
li2 = []
for x in li:
for y in x:
li2.append(y)