Last active
April 29, 2020 14:36
-
-
Save jag-k/bff866972afc3b30f2f08cd1f5f6719e 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
from io import TextIOWrapper | |
from sys import stdout | |
from typing import List | |
def print_matrix(matrix: List[List[int]], file: TextIOWrapper = stdout) -> None: | |
width, height = len(matrix), len(matrix[0]) | |
# max length for beautify | |
l: int = len(str(1 + max( | |
width, | |
height, | |
max(map(max, matrix)) | |
))) | |
h = len(str(height)) | |
# print column index | |
file.write( | |
" " * (h + 1) + " ".join(str(i).rjust(l) for i in range(width)) + "\n" + | |
"\n".join( | |
str(y).ljust(h) + ":[" + | |
" ".join(str(x).rjust(l) for x in matrix[y]) + "]" | |
for y in range(height) | |
) + "\n" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
строку
h = len(str(height)) - 1
нужно заменить на
h = len(str(height+1)) - 1