0
0
Pythonprogramming~20 mins

Lambda with map() in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Lambda Map Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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)
A[1, 4, 9, 16]
B[1, 2, 3, 4]
C[3, 6, 9, 12]
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Remember map applies the function to each item in the list.
โ“ Predict Output
intermediate
2: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)
ASyntaxError
B[0, 1, 2, 3, 4]
C[0, 1, 0, 3, 0]
D[0, 0, 2, 0, 4]
Attempts:
2 left
๐Ÿ’ก Hint
The lambda replaces odd numbers with zero.
โ“ Predict Output
advanced
2: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)
A['APPLE', 'BANANA', 'CHERRY']
B[['A', 'P', 'P', 'L', 'E'], ['B', 'A', 'N', 'A', 'N', 'A'], ['C', 'H', 'E', 'R', 'R', 'Y']]
C[['apple'], ['banana'], ['cherry']]
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
The inner map converts each character to uppercase.
โ“ Predict Output
advanced
2: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)
A[5, 7, 9]
B[1, 2, 3, 4, 5, 6]
C[4, 10, 18]
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
map applies the lambda to pairs of elements from both lists.
๐Ÿง  Conceptual
expert
2: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)))
ASyntaxError
BTypeError
CNameError
DNo error, outputs [6, 8]
Attempts:
2 left
๐Ÿ’ก Hint
Check the lambda syntax and how map is used.