1

list_of_lists = [[1, 2, 3, 4], [1, 5, 6, 7], [1, 8, 9, 10]]

I would like to get to: transposed_list = [[1, 2, 5, 8], [1, 3, 6, 9], [1, 4, 7, 10]]

In other words, only transpose from the 2nd element in the list, keeping the first element in place.

Marwari
  • 13
  • 2
  • Does this answer your question? [Transpose list of lists](https://stackoverflow.com/questions/6473679/transpose-list-of-lists) – Kafels May 13 '21 at 20:29

1 Answers1

0

Try:

list_of_lists = [[1, 2, 3, 4], [1, 5, 6, 7], [1, 8, 9, 10]]

out = [
    [list_of_lists[i][0]] + list(l)
    for i, l in enumerate(zip(*(l[1:] for l in list_of_lists)))
]
print(out)

Prints:

[[1, 2, 5, 8], [1, 3, 6, 9], [1, 4, 7, 10]]
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91