Unpack Nested Lists
Data often arrives in groups: several small lists inside one larger list. The function flatten receives a list nested, where each element is also a list of numbers. Return one flat list with all the numbers in the same order they appeared inside the nested lists.
Примеры
Ввод
[[1, 2], [3, 4]]Вывод
[1, 2, 3, 4]Ввод
[[]]Вывод
[]Ввод
[[1], [2], [3]]Вывод
[1, 2, 3]Нужно реализовать
def flatten(nested: list[list[int]]) -> list[int]:
Теги
lists
Přihlaste se, abyste viděli historii odevzdání
Přihlásit sePřihlaste se, abyste mohli použít AI mentora
Přihlásit seVisible tests
1
Input
[[1,2],[3,4]]Expected
[1,2,3,4]2
Input
[[]]Expected
[]3
Input
[[1],[2],[3]]Expected
[1,2,3]4
Input
[]Expected
[]5
Input
[[5,6,7]]Expected
[5,6,7]6
Input
[[3,4],[1,2]]Expected
[3,4,1,2]Focus radio
Paused · SomaFM · Fluid