Read a Matrix Column

A matrix can be stored inside a string: each text line is one table row, and the numbers are separated by spaces. The function matrix_column receives matrix_string and a column index, where counting starts from 1. Take the number at that position from each row and return the resulting column as a list of integers.

Примеры

Ввод
"1 2 3\n4 5 6\n7 8 9", 1
Вывод
[1, 4, 7]
Ввод
"1 2 3\n4 5 6\n7 8 9", 2
Вывод
[2, 5, 8]
Ввод
"1 2 3\n4 5 6\n7 8 9", 3
Вывод
[3, 6, 9]

Нужно реализовать

def matrix_column(matrix_string: str, index: int) -> list[int]:

Теги

arraystrings
PostgreSQLv16

Ovdje će se prikazati rezultat izvršavanja koda

Visible tests
1
Input
"1 2 3\n4 5 6\n7 8 9", 1
Expected[1,4,7]
2
Input
"1 2 3\n4 5 6\n7 8 9", 2
Expected[2,5,8]
3
Input
"1 2 3\n4 5 6\n7 8 9", 3
Expected[3,6,9]
4
Input
"89 1903 3\n18 3 1\n9 4 800", 2
Expected[1903,3,4]
5
Input
"1 2 3\n4 5 6\n7 8 9", 0
Expected[3,6,9]
6
Input
"1 2 3\n4 5 6\n7 8 9", -1
Expected[2,5,8]
Focus radio
Paused · SomaFM · Fluid