First and Last
Lists often need a quick way to pull out only the beginning and the end, such as the first and last stop of a route. Write a function make_ends that takes a non-empty list of numbers nums. Return a new list with two elements: the first and last elements of 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
Prijavi se da vidiš povijest predaja
PrijavaPrijavi se da koristiš AI mentora
PrijavaVisible 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
[3,2,1]Expected
[3,1]6
Input
[1,2,3,1]Expected
[1,1]Focus radio
Paused · SomaFM · Fluid