0

I'm trying to do something fairly simple. Given a matrix, I want to combine the column elements such that:

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

...and I want to return:

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

This loop might be very simple, but I keep running into iteration errors or index out of range errors.

Thanks!

Jeremy Thomas
  • 5,590
  • 8
  • 40
  • 80

1 Answers1

2

How about using zip():

zip(*a)
jh314
  • 25,902
  • 15
  • 60
  • 80