Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created January 21, 2019 17:42
Show Gist options
  • Save vlad-bezden/36049f4dccf6cf18208a96f4eacbf62d to your computer and use it in GitHub Desktop.
Save vlad-bezden/36049f4dccf6cf18208a96f4eacbf62d to your computer and use it in GitHub Desktop.
Creates 2D array (matrix)
"""
Creates 2D matrix
"""
def matrix(rows, cols, start=0):
return [[c + start + r * cols for c in range(cols)] for r in range(rows)]
assert matrix(2, 3, 1) == [[1, 2, 3], [4, 5, 6]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment