Challenge - 5 Problems
Filter Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
What is the output of this filter() example?
Consider the following Python code using
filter(). What will be printed?Python
numbers = [1, 2, 3, 4, 5, 6] result = list(filter(lambda x: x % 2 == 0, numbers)) print(result)
Attempts:
2 left
๐ก Hint
filter() keeps items where the function returns True.
โ Incorrect
The lambda function returns True for even numbers only, so filter() keeps 2, 4, and 6.
โ Predict Output
intermediate2:00remaining
What does this filter() call return?
What is the output of this code snippet?
Python
words = ['apple', 'banana', 'cherry', 'date'] result = list(filter(lambda w: len(w) > 5, words)) print(result)
Attempts:
2 left
๐ก Hint
filter() keeps words longer than 5 letters.
โ Incorrect
Only 'banana' and 'cherry' have length greater than 5.
โ Predict Output
advanced2:00remaining
What is the output of this filter() with None as function?
What will this code print?
Python
items = [0, 1, False, True, '', 'Hello', None, [], [1, 2]] result = list(filter(None, items)) print(result)
Attempts:
2 left
๐ก Hint
filter(None, iterable) removes all falsey values.
โ Incorrect
filter(None, ...) removes items that are false when converted to bool, keeping only truthy values.
โ Predict Output
advanced2:00remaining
What is the output of this chained filter() example?
What will this code print?
Python
data = range(10) result = list(filter(lambda x: x % 2 == 0, filter(lambda x: x > 4, data))) print(result)
Attempts:
2 left
๐ก Hint
First filter keeps numbers > 4, second filter keeps even numbers.
โ Incorrect
Numbers > 4 are 5,6,7,8,9. Among these, even numbers are 6 and 8.
๐ง Conceptual
expert2:00remaining
Which option causes a TypeError when used with filter()?
Which of these options will cause a TypeError when passed as the function argument to filter()?
Attempts:
2 left
๐ก Hint
filter() expects a function or None as first argument.
โ Incorrect
Passing an integer instead of a function or None causes TypeError.