Skip to content

Instantly share code, notes, and snippets.

@ejmg
Created November 3, 2016 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejmg/304f52a9d306e783b53aa2f3e17f10e5 to your computer and use it in GitHub Desktop.
Save ejmg/304f52a9d306e783b53aa2f3e17f10e5 to your computer and use it in GitHub Desktop.
Print the contents of a square 2d array as a nicely formatted string
# Prints a square 2d array nicely with spacing of elements
# Modify frmt for the number of elements in each row, as well as the matrix itself of course
newline, empty, frmt = "\n", "", "{:4}"
print(newline.join([empty.join([frmt.format(element) for element in row])
for row in matrix]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment