List of all diagonals in a matrix without using numpy - Python 3


April 2019


9 time


Let's say I got the following matrix:

[[5,4,3,2], [8,7,6,5], [4,3,2,0]]

I want to create 2 seperate functions that create a list of all diagonals from right to left, and from left to right without using the numpy module!

for e.x:

[[4], [8,3], [5,7,2], [4,6,0], [3,5], [2]]   # these are the right to left diagonals

I tried several different ways but with no success. also, I scanned stack overflow pretty massivly for answers, but did't find any that don't contain numpy.

0 answers