1

I want to join list of lists by element such that

lst = [['a','b','c'], [1,2,3], ['x','y','z'], [4,5,6]]

becomes

res = [['a',1,'x',4], ['b',2,'y',5], ['c',3,'z',6]]

I'v tried using list comprehension, concatenate and map, but haven't had any luck with it yet. (New to python)

1 Answers1

3

Try zip (similar question: Transpose list of lists):

>>> lst = [["a","b","c"], [1,2,3], ["x","y","z"], [4,5,6]]
>>> res = [list(zipped) for zipped in zip(*lst)]
>>> res
[['a', 1, 'x', 4], ['b', 2, 'y', 5], ['c', 3, 'z', 6]]
mfrackowiak
  • 1,294
  • 8
  • 11