mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
Add missing type hints in matrix
directory (#6612)
* Update count_islands_in_matrix.py * Update matrix_class.py * Update matrix_operation.py * Update nth_fibonacci_using_matrix_exponentiation.py * Update searching_in_sorted_matrix.py * Update count_islands_in_matrix.py * Update matrix_class.py * Update matrix_operation.py * Update rotate_matrix.py * Update sherman_morrison.py * Update spiral_print.py * Update count_islands_in_matrix.py * formatting * formatting * Update matrix_class.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
a84fb58271
commit
46842e8c5b
@ -8,7 +8,7 @@ https://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-ar
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def make_matrix(row_size: int = 4) -> list[list]:
|
||||
def make_matrix(row_size: int = 4) -> list[list[int]]:
|
||||
"""
|
||||
>>> make_matrix()
|
||||
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
|
||||
@ -25,7 +25,7 @@ def make_matrix(row_size: int = 4) -> list[list]:
|
||||
return [[1 + x + y * row_size for x in range(row_size)] for y in range(row_size)]
|
||||
|
||||
|
||||
def rotate_90(matrix: list[list]) -> list[list]:
|
||||
def rotate_90(matrix: list[list[int]]) -> list[list[int]]:
|
||||
"""
|
||||
>>> rotate_90(make_matrix())
|
||||
[[4, 8, 12, 16], [3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13]]
|
||||
@ -37,7 +37,7 @@ def rotate_90(matrix: list[list]) -> list[list]:
|
||||
# OR.. transpose(reverse_column(matrix))
|
||||
|
||||
|
||||
def rotate_180(matrix: list[list]) -> list[list]:
|
||||
def rotate_180(matrix: list[list[int]]) -> list[list[int]]:
|
||||
"""
|
||||
>>> rotate_180(make_matrix())
|
||||
[[16, 15, 14, 13], [12, 11, 10, 9], [8, 7, 6, 5], [4, 3, 2, 1]]
|
||||
@ -49,7 +49,7 @@ def rotate_180(matrix: list[list]) -> list[list]:
|
||||
# OR.. reverse_column(reverse_row(matrix))
|
||||
|
||||
|
||||
def rotate_270(matrix: list[list]) -> list[list]:
|
||||
def rotate_270(matrix: list[list[int]]) -> list[list[int]]:
|
||||
"""
|
||||
>>> rotate_270(make_matrix())
|
||||
[[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]
|
||||
@ -61,22 +61,22 @@ def rotate_270(matrix: list[list]) -> list[list]:
|
||||
# OR.. transpose(reverse_row(matrix))
|
||||
|
||||
|
||||
def transpose(matrix: list[list]) -> list[list]:
|
||||
def transpose(matrix: list[list[int]]) -> list[list[int]]:
|
||||
matrix[:] = [list(x) for x in zip(*matrix)]
|
||||
return matrix
|
||||
|
||||
|
||||
def reverse_row(matrix: list[list]) -> list[list]:
|
||||
def reverse_row(matrix: list[list[int]]) -> list[list[int]]:
|
||||
matrix[:] = matrix[::-1]
|
||||
return matrix
|
||||
|
||||
|
||||
def reverse_column(matrix: list[list]) -> list[list]:
|
||||
def reverse_column(matrix: list[list[int]]) -> list[list[int]]:
|
||||
matrix[:] = [x[::-1] for x in matrix]
|
||||
return matrix
|
||||
|
||||
|
||||
def print_matrix(matrix: list[list]) -> None:
|
||||
def print_matrix(matrix: list[list[int]]) -> None:
|
||||
for i in matrix:
|
||||
print(*i)
|
||||
|
||||
|
Reference in New Issue
Block a user