Skip to content

Instantly share code, notes, and snippets.

@jag-k
Last active April 29, 2020 14:36
Show Gist options
  • Save jag-k/bff866972afc3b30f2f08cd1f5f6719e to your computer and use it in GitHub Desktop.
Save jag-k/bff866972afc3b30f2f08cd1f5f6719e to your computer and use it in GitHub Desktop.
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"
)
@yoloroy
Copy link

yoloroy commented Apr 29, 2020

строку
h = len(str(height)) - 1
нужно заменить на
h = len(str(height+1)) - 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment