Read a Matrix Row
A matrix is often passed as plain text: rows are separated by line breaks, and numbers inside each row are separated by spaces. The function matrix_row receives matrix_string and a row index, where counting starts from 1. Find that row, convert its values to integers, and return them as a list.
Примеры
Ввод
"1 2 3\n4 5 6\n7 8 9", 1Вывод
[1, 2, 3]Ввод
"1 2 3\n4 5 6\n7 8 9", 2Вывод
[4, 5, 6]Ввод
"1 2 3\n4 5 6\n7 8 9", 3Вывод
[7, 8, 9]Нужно реализовать
def matrix_row(matrix_string: str, index: int) -> list[int]:
Теги
arraystrings
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachVisible tests
1
Input
"1 2 3\n4 5 6\n7 8 9", 1Expected
[1,2,3]2
Input
"1 2 3\n4 5 6\n7 8 9", 2Expected
[4,5,6]3
Input
"1 2 3\n4 5 6\n7 8 9", 3Expected
[7,8,9]4
Input
"7 8\n9 10", 2Expected
[9,10]5
Input
"1 2 3\n4 5 6\n7 8 9", -1Expected
[4,5,6]6
Input
"1 2 3\n4 5 6\n7 8 9", 0Expected
[7,8,9]Focus radio
Paused · SomaFM · Fluid