how to extract numbers from each position of a python list of lists -
i have list :
n=[[0,3,4], [0,1,2,9,3], [0,3]]
how use ths list list each list item being number each positon of list items in n
new list looks like:
newlist=[[0,0,0], [3,1,3], [4,2] ,[9], [3]]
so first item in newlist sublist contains first number in n[0], first number in n[1], , first number in n[2]. next sublist in n same second positions.
could make use of izip_longest
, filter out default values, eg:
from itertools import izip_longest n=[[0,3,4], [0,1,2,9,3], [0,3]] new_list = [[el el in items if el not none] items in izip_longest(*n)] # [[0, 0, 0], [3, 1, 3], [4, 2], [9], [3]]
Comments
Post a Comment