Filter even numbers
Input
filter_list([1, 2, 3, 4], lambda x: x % 2 == 0)
Output
[2, 4]
The predicate keeps only numbers divisible by 2.
Full lesson preview
Return a new list containing only the elements that satisfy a given predicate function.
Problem statement
Task
Examples
Input
filter_list([1, 2, 3, 4], lambda x: x % 2 == 0)
Output
[2, 4]
The predicate keeps only numbers divisible by 2.
Input format
Output format
Constraints
Samples
Input
filter_list(['apple', 'banana', 'avocado'], lambda s: s.startswith('a'))
Output
['apple', 'avocado']
Keeps only strings that start with 'a'.