Created
November 3, 2016 01:48
-
-
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
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
# 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