Challenge - 5 Problems
Map Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of map() with lambda and list
What is the output of this Python code?
Python
result = list(map(lambda x: x**2, [1, 2, 3, 4])) print(result)
Attempts:
2 left
๐ก Hint
Think about what the lambda function does to each element.
โ Incorrect
The lambda function squares each number. So 1**2=1, 2**2=4, 3**2=9, 4**2=16.
โ Predict Output
intermediate2:00remaining
map() with multiple iterables
What is the output of this code snippet?
Python
def add(x, y): return x + y result = list(map(add, [1, 2, 3], [4, 5, 6])) print(result)
Attempts:
2 left
๐ก Hint
map applies the function to pairs of elements from both lists.
โ Incorrect
The add function sums pairs: 1+4=5, 2+5=7, 3+6=9.
โ Predict Output
advanced2:00remaining
map() with filter and string conversion
What is the output of this code?
Python
numbers = [10, 15, 20, 25] result = list(map(str, filter(lambda x: x % 20 == 0, numbers))) print(result)
Attempts:
2 left
๐ก Hint
filter keeps only numbers divisible by 20, then map converts them to strings.
โ Incorrect
Only 20 is divisible by 20, so filter returns [20]. map converts it to ['20'].
โ Predict Output
advanced2:00remaining
map() with None as function argument
What is the output of this code?
Python
result = list(map(None, [1, 2, 3])) print(result)
Attempts:
2 left
๐ก Hint
In Python 3, map() requires a callable function, None is not callable.
โ Incorrect
Passing None as the function causes a TypeError because None is not callable.
๐ง Conceptual
expert3:00remaining
Behavior of map() with infinite iterator
Consider this code:
import itertools
result = map(lambda x: x*2, itertools.count(1))
output = []
for i, val in enumerate(result):
if i == 5:
break
output.append(val)
print(output)
What is the output printed?
Attempts:
2 left
๐ก Hint
itertools.count(1) generates numbers starting at 1 endlessly; map doubles them; loop stops after 5 items.
โ Incorrect
The loop collects first 5 doubled numbers: 1*2=2, 2*2=4, 3*2=6, 4*2=8, 5*2=10.