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 nones, 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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -