This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Lambda, map, and filter, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
What is a lambda?
Answer: A small anonymous function
Why: A lambda defines a function in a single expression.
What does map return in Python 3?
Answer: An iterator
Why: map is lazy in Python 3; wrap it in list() to see every value.
What is printed?
print(list(map(lambda x: x * 2, [1, 2])))Answer: [2, 4]
Why: Each value is doubled, and list() materialises the map iterator.
Which expression keeps numbers greater than 2?
Answer: filter(lambda x: x > 2, nums)
Why: filter takes a predicate first and an iterable second.
Complete the anonymous function.
double = ____ n: n * 2
print(double(3))Answer: lambda
Why: lambda starts an anonymous function expression.
Complete the conversion so the map result can be printed as a list.
print(____(map(str, [1, 2])))Answer: list
Why: list() consumes the map iterator and builds a list.
Complete the operator that tests even numbers.
nums = [1, 2, 3, 4]
print(list(filter(lambda n: n ____ 2 == 0, nums)))Answer: %
Why: n % 2 == 0 is true when n is even.
Complete the function that squares each number.
nums = [1, 2, 3]
print(list(map(____, nums)))Answer: lambda n: n * n
Why: The lambda receives one number and returns its square.
What is the output?
print((lambda n: n + 3)(4))Answer: 7
Why: The lambda is called immediately with 4, producing 7.
What does this code print?
print(list(map(lambda s: s.upper(), ["a", "b"])))Answer: ['A', 'B']
Why: Each string is uppercased, and list() shows both results.
What does the program output?
print(list(filter(lambda n: n % 2 == 1, [1, 2, 3, 4])))Answer: [1, 3]
Why: The odd values are 1 and 3.
What appears on the screen?
print(list(map(len, ["a", "bb", "ccc"])))Answer: [1, 2, 3]
Why: The lengths are 1, 2, and 3.
Try the questions first
Open the practice page for Python Lambda, map, and filter and answer the same 12 questions with instant feedback.