Matching Edges
Checking the first and last elements is useful when a list should start and end with the same value. Write a function same_first_last that takes a list of numbers nums. Return True if the list is not empty and its first element equals its last element. If the list is empty or the edge values are different, return False.
Примеры
Ввод
[1, 2, 3]Вывод
FalseВвод
[1, 2, 3, 1]Вывод
TrueВвод
[1, 2, 1]Вывод
TrueНужно реализовать
def same_first_last(nums: list[int]) -> bool:
Теги
listsarray
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]Expected
False2
Input
[1,2,3,1]Expected
True3
Input
[1,2,1]Expected
True4
Input
[]Expected
False5
Input
[5]Expected
True6
Input
[0]Expected
TrueFocus radio
Paused · SomaFM · Fluid