python - Merge multiple 2d lists considering axis in order -


my purpose combine multiple 2d list in order such as:

a = [[1,2],[3,1]] b= [[3,6],[2,9]] c = [[5,1],[8,10]] expected: [[1,2,3,6,5,1],[3,1,2,9,8,10]] 

following other's advice site, tried use collections module code below:

from collections import counter = [[1,2],[3,1]] b= [[3,6],[2,9]] c = [[5,1],[8,10]] d = [[k,v] k,v in (counter(dict(a)) + counter(dict(b))+ counter(dict(c))).items()] print d 

however, result [[1, 2], [3, 1], [3, 6], [2, 9]] not expected.

do have idea solve problem? maybe if there function or module consider axis combine lists.

you can use zip , list comprehension:

>>> = [[1,2],[3,1]] >>> b = [[3,6],[2,9]] >>> c = [[5,1],[8,10]] >>> [x+y+z x,y,z in zip(a, b, c)] [[1, 2, 3, 6, 5, 1], [3, 1, 2, 9, 8, 10]] >>> 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -