Last Even Values
Sometimes you need to take only the last matching values from a large list while keeping their original order. Write a function even_numbers that takes a list arr and a number n. First find all even numbers, then return the last n of them in the same order they appeared in the original list.
Примеры
Ввод
[1, 2, 3, 4, 5, 6, 7, 8, 9], 3Вывод
[4, 6, 8]Ввод
[-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2Вывод
[-8, 26]Ввод
[6, -25, 3, 7, 5, 5, 7, -3, 23], 1Вывод
[6]Нужно реализовать
def even_numbers(arr: list[int], n: int) -> list[int]:
Теги
listsarray
Accedi per vedere la cronologia degli invii
AccediAccedi per usare l'AI Mentor
AccediVisible tests
1
Input
[1,2,3,4,5,6,7,8,9], 3Expected
[4,6,8]2
Input
[-22,5,3,11,26,-6,-7,-8,-9,-8,26], 2Expected
[-8,26]3
Input
[6,-25,3,7,5,5,7,-3,23], 1Expected
[6]4
Input
[2,4,6,8], 4Expected
[2,4,6,8]5
Input
[2,4,6,8], 2Expected
[6,8]6
Input
[1,2,3,4,5,6,7,8,9], -3Expected
[8]Focus radio
Paused · SomaFM · Fluid