>>> transpose([[1,2],[3,4]]) # doctest: +ELLIPSIS >> transpose([[1,2],[3,4]], return_map=False) [[1, 3], [2, 4]] >>> transpose([1, [2, 3]]) Traceback (most recent call last): ... TypeError: Expected a matrix, got int/list instead
(
matrix: list[list[int]], return_map: bool = True
)
| 93 | |
| 94 | |
| 95 | def transpose( |
| 96 | matrix: list[list[int]], return_map: bool = True |
| 97 | ) -> list[list[int]] | map[list[int]]: |
| 98 | """ |
| 99 | >>> transpose([[1,2],[3,4]]) # doctest: +ELLIPSIS |
| 100 | <map object at ... |
| 101 | >>> transpose([[1,2],[3,4]], return_map=False) |
| 102 | [[1, 3], [2, 4]] |
| 103 | >>> transpose([1, [2, 3]]) |
| 104 | Traceback (most recent call last): |
| 105 | ... |
| 106 | TypeError: Expected a matrix, got int/list instead |
| 107 | """ |
| 108 | if _check_not_integer(matrix): |
| 109 | if return_map: |
| 110 | return map(list, zip(*matrix)) |
| 111 | else: |
| 112 | return list(map(list, zip(*matrix))) |
| 113 | raise TypeError("Expected a matrix, got int/list instead") |
| 114 | |
| 115 | |
| 116 | def minor(matrix: list[list[int]], row: int, column: int) -> list[list[int]]: |
no test coverage detected