Answer key · 12 questions

Python Lambda, map, and filter Exercises With Answers

All 12 questions for Python Lambda, map, and filter in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

What is a lambda?

  1. A type of list
  2. A loop with a condition
  3. A small anonymous functioncorrect
  4. A module for math

Answer: A small anonymous function

Why: A lambda defines a function in a single expression.

02 · Multiple choice

What does map return in Python 3?

  1. A list
  2. A dictionary
  3. A string
  4. An iteratorcorrect

Answer: An iterator

Why: map is lazy in Python 3; wrap it in list() to see every value.

03 · Multiple choice

What is printed?

print(list(map(lambda x: x * 2, [1, 2])))
  1. [1, 4]
  2. [2, 2]
  3. [1, 2]
  4. [2, 4]correct

Answer: [2, 4]

Why: Each value is doubled, and list() materialises the map iterator.

04 · Multiple choice

Which expression keeps numbers greater than 2?

  1. filter(lambda x: x > 2, nums)correct
  2. map(lambda x: x > 2, nums)
  3. filter(nums, lambda x: x > 2)
  4. list(lambda x: x > 2, nums)

Answer: filter(lambda x: x > 2, nums)

Why: filter takes a predicate first and an iterable second.

05 · Fill in the blank

Complete the anonymous function.

double = ____ n: n * 2
print(double(3))

Answer: lambda

Why: lambda starts an anonymous function expression.

06 · Fill in the blank

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.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

What is the output?

print((lambda n: n + 3)(4))

Answer: 7

Why: The lambda is called immediately with 4, producing 7.

10 · Predict output

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.

11 · Predict output

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.

12 · Predict output

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.

Practice this lesson