data structures - Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped -
data structures - Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped -
i have 2 lists
a = [1,2,3] b = [9,10]
i want combine (zip) these 2 lists 1 list c
such
c = [(1,9), (2,10), (3, )]
is there function in standard library in python this?
what seek itertools.izip_longest
>>> = [1,2,3] >>> b = [9,10] >>> in itertools.izip_longest(a,b): print ... (1, 9) (2, 10) (3, none)
edit 1: if want rid of none
s, try:
>>> in (filter(none, pair) pair in itertools.izip_longest(a,b)): print (1, 9) (2, 10) (3,)
edit 2: in response steveha's comment:
filter(lambda p: p not none, pair) pair in itertools.izip_longest(a,b)
python data-structures
Comments
Post a Comment