Last active
May 13, 2017 11:25
-
-
Save horpto/f612784729b9c1a913b695988e18aad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
def diags(matrix): | |
x = len(matrix[0]) | |
yield [matrix[i][i] for i in range(x)] | |
yield [matrix[i][x - 1 - i] for i in range(x)] | |
for i in range(1, x): | |
row1 = [] | |
row2 = [] | |
row3 = [] | |
row4 = [] | |
for j in range(i): | |
row1.append(matrix[x - i + j][j]) | |
row2.append(matrix[j][x - i + j]) | |
row3.append(matrix[j][i-1 - j]) | |
row4.append(matrix[x - 1 - j][x - i + j]) | |
yield row1 | |
yield row2 | |
yield row3 | |
yield row4 | |
matr = [[i * j for j in range(15)] for i in range(15)] | |
pprint(matr) | |
print() | |
for row in diags(matr): | |
print(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment