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
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónVisible tests
1
Input
"1 2 3\n4 5 6\n7 8 9", 1Expected
[1,4,7]2
Input
"1 2 3\n4 5 6\n7 8 9", 2Expected
[2,5,8]3
Input
"1 2 3\n4 5 6\n7 8 9", 3Expected
[3,6,9]4
Input
"89 1903 3\n18 3 1\n9 4 800", 2Expected
[1903,3,4]5
Input
"1 2 3\n4 5 6\n7 8 9", 0Expected
[3,6,9]6
Input
"1 2 3\n4 5 6\n7 8 9", -1Expected
[2,5,8]Focus radio
Paused · SomaFM · Fluid