Keep even numbers
Input
make_filter(lambda x: x % 2 == 0)([1, 2, 3, 4])
Output
[2, 4]
The produced function filters the iterable to include only even numbers.
Full lesson preview
Create a factory that returns reusable filter functions (optionally negated) to apply to any iterable.
Problem statement
Task
Examples
Input
make_filter(lambda x: x % 2 == 0)([1, 2, 3, 4])
Output
[2, 4]
The produced function filters the iterable to include only even numbers.
Input format
Output format
Constraints
Samples
Input
make_filter(lambda s: 'ap' in s.lower())(['Apple','banana','Grape'])
Output
['Apple', 'Grape']
Case-insensitive substring match; 'Apple' and 'Grape' include 'ap'.