Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Last active March 9, 2018 16:26
Show Gist options
  • Save jordanhudgens/5484a152c1e2f118d5ba1d713a9ea9e4 to your computer and use it in GitHub Desktop.
Save jordanhudgens/5484a152c1e2f118d5ba1d713a9ea9e4 to your computer and use it in GitHub Desktop.
# [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