First and Last
The edge values of a list are often meaningful on their own, such as the start and end of a route or range. Write a function make_ends that takes a non-empty list nums. Return a new list with two elements: the first and last values from the original list.
Примеры
Ввод
[1, 2, 3]Вывод
[1, 3]Ввод
[1, 2, 3, 4]Вывод
[1, 4]Ввод
[7, 4, 6, 2]Вывод
[7, 2]Нужно реализовать
def make_ends(nums: list[int]) -> list[int]:
Теги
listsarray
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
[1,2,3]Expected
[1,3]2
Input
[1,2,3,4]Expected
[1,4]3
Input
[7,4,6,2]Expected
[7,2]4
Input
[5]Expected
[5,5]5
Input
[9,9]Expected
[9,9]6
Input
[0,0,0]Expected
[0,0]Focus radio
Paused · SomaFM · Fluid