Skip to content

Transpose a list in Python

Advertisements
def transpose(l):
  return list(zip(*l))
print(transpose([[0,0,0], [1, 1, 1], [2, 2, 2], [3, 3, 3]]))

#[(0, 1, 2, 3), (0, 1, 2, 3), (0, 1, 2, 3)]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.