Challenge - 5 Problems
Lambda Map Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of lambda with map() on a list
What is the output of this Python code?
Python
numbers = [1, 2, 3, 4] result = list(map(lambda x: x * 3, numbers)) print(result)
Attempts:
2 left
๐ก Hint
Remember map applies the function to each item in the list.
โ Incorrect
The lambda multiplies each number by 3, so the output list is each original number times 3.
โ Predict Output
intermediate2:00remaining
Result of map with lambda and filter logic
What is the output of this code snippet?
Python
values = [0, 1, 2, 3, 4] result = list(map(lambda x: x if x % 2 == 0 else 0, values)) print(result)
Attempts:
2 left
๐ก Hint
The lambda replaces odd numbers with zero.
โ Incorrect
For each number, if it is even, keep it; if odd, replace with 0. So 1 and 3 become 0.
โ Predict Output
advanced2:00remaining
Output of nested lambda with map on strings
What does this code print?
Python
words = ['apple', 'banana', 'cherry'] result = list(map(lambda w: list(map(lambda c: c.upper(), w)), words)) print(result)
Attempts:
2 left
๐ก Hint
The inner map converts each character to uppercase.
โ Incorrect
Each word is mapped to a list of its uppercase letters, so the result is a list of lists of uppercase letters.
โ Predict Output
advanced2:00remaining
Output of map with lambda and multiple iterables
What is the output of this code?
Python
a = [1, 2, 3] b = [4, 5, 6] result = list(map(lambda x, y: x + y, a, b)) print(result)
Attempts:
2 left
๐ก Hint
map applies the lambda to pairs of elements from both lists.
โ Incorrect
The lambda adds corresponding elements: 1+4=5, 2+5=7, 3+6=9.
๐ง Conceptual
expert2:00remaining
Error raised by incorrect lambda syntax in map
What error does this code raise?
Python
result = list(map(lambda x: x * 2 if x > 2 for x in range(5)))
Attempts:
2 left
๐ก Hint
Check the lambda syntax and how map is used.
โ Incorrect
The lambda expression is invalid because it mixes a conditional expression with a for loop inside lambda, causing SyntaxError.