Last active
March 9, 2018 16:26
-
-
Save jordanhudgens/5484a152c1e2f118d5ba1d713a9ea9e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# [0, 1, 2, 3, 4] | |
# [1, 2, 3, 4, 5] | |
# [2, 3, 4, 5, 6] | |
# [3, 4, 5, 6, 7] | |
# [4, 5, 6, 7, 8] | |
def manual_incrementing_matrix(n): | |
matrix = [ [ None for y in range( n ) ] for x in range( n ) ] | |
""" | |
[ | |
[None, None, None, None, None], | |
[None, None, None, None, None], | |
[None, None, None, None, None], | |
[None, None, None, None, None], | |
[None, None, None, None, None] | |
] | |
""" | |
counter = 0 | |
for idx, el in enumerate(matrix): | |
for nested_idx, nested_el in enumerate(el): | |
matrix[idx][nested_idx] = counter + nested_idx | |
counter += 1 | |
return matrix | |
print(manual_incrementing_matrix(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment