Square even numbers
Input
filter_transform([1,2,3,4], lambda x: x%2==0, lambda x: x*x)
Output
[4, 16]
Keeps even numbers and squares them.
Full lesson preview
Filter a list with a predicate and transform each passing element with a mapping function using a comprehension.
Problem statement
Task
Examples
Input
filter_transform([1,2,3,4], lambda x: x%2==0, lambda x: x*x)
Output
[4, 16]
Keeps even numbers and squares them.
Input format
Output format
Constraints
Samples
Input
filter_transform(['a','abcd','abcde'], lambda s: len(s)>3, lambda s: s.upper())
Output
['ABCD', 'ABCDE']
Filter strings longer than 3 and convert to uppercase.