PReddy PReddy - 16 days ago 7
Python Question

Python : Get the particular index value from all the lists at a single shot and create another list

For example, consider the below nested lists.

L1 = [[1,2,3],[4,5,6],[7,8,9]]
L2 = [[11,22,33],[44,55,66]]
L3 = [[111,222,333],[444,555,666],[777,888,999]]
L4 = [12,13,14]


In a iteration i required,

output1 = [1,4,7,11,44,111,444,777,12]
output2 = [2,5,8,22,55,222,555,888,13]
output3 = [3,6,9,33,66,333,666,999,14]

Answer

Try this:

L = L1+L2+L3+[L4]
output1 = [l[0] for l in L]
output2 = [l[1] for l in L]
output3 = [l[2] for l in L]
Comments