python matrix - need all diagonals of a matrix

Viewed 14

I need to insert all the diagonals(not just two) of a square matrix into a list. How can I do it ?

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

list should be : ls = [[1], [4,2], [7,5,3], [8,6], [9]]

Please avoid giving one liner solutions such as list comprehension. I just want to understand the logic which can give me this result.

0 Answers
Related