I'm trying to print the diagonals for a 2d array starting with the bottom left corner and moving towards the top right corner. I've managed to print the first half of the matrix but I got stuck when I have to print the second part of it and I'm hoping somebody can give me a clue how to continue. Here is what I have:
matrix = [["A", "B", "C", "D"],
["E", "F", "G", "H"],
["I", "J", "K", "L"],
["M", "N", "O", "P"],
["Q", "R", "S", "T"]]
and the partial function that print the diagonals up to a point:
def diagonal_matrix_print(input_matrix):
width = len(input_matrix[0])
height = len(input_matrix)
start_row = height - 1
first_row = 0
for start_row in reversed(range(0, height)):
i = start_row
for column in range(0, width):
if i == height:
start_row = start_row - 1
break
print input_matrix[i][column]
i = i + 1
print
The issue I'm facing is printing the diagonals that start with the second half of the matrix - B G L, C H, D
I tried using another 2 for loops for it like:
for row in range (0, height -1):
i = row
for start_column in range(1, width):
print input_matrix[i][start_column]
i = i + 1
but when the row value changes to 1, is not printing the diagonal anymore...