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
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible 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