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
  • 6,240
  • 9
  • 47
  • 92

1 Answers1

2

How about using zip():

zip(*a)
jh314
  • 27,144
  • 16
  • 62
  • 82