Challenge - 5 Problems
Map Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of map() with a lambda function
What is the output of this Python code using
map()?Data Analysis Python
numbers = [1, 2, 3, 4] result = list(map(lambda x: x**2, numbers)) print(result)
Attempts:
2 left
💡 Hint
Remember,
map() applies the function to each element in the list.✗ Incorrect
The lambda function squares each number. So 1²=1, 2²=4, 3²=9, 4²=16.
❓ data_output
intermediate2:00remaining
Mapping a dictionary to a list
What is the output of this code that uses
map() on a dictionary's keys?Data Analysis Python
data = {'a': 1, 'b': 2, 'c': 3}
result = list(map(str.upper, data))
print(result)Attempts:
2 left
💡 Hint
Mapping applies to dictionary keys by default.
✗ Incorrect
The
map() applies str.upper to each key: 'a' → 'A', 'b' → 'B', 'c' → 'C'.🔧 Debug
advanced2:00remaining
Identify the error in map() usage
What error does this code raise when run?
Data Analysis Python
values = [1, 2, 3] result = list(map(lambda x: x + y, values)) print(result)
Attempts:
2 left
💡 Hint
Check if all variables inside the lambda are defined.
✗ Incorrect
The variable 'y' is not defined anywhere, so Python raises a NameError.
🚀 Application
advanced2:00remaining
Using map() to convert string numbers to integers
Given a list of strings representing numbers, which option correctly converts them to integers using
map()?Data Analysis Python
str_numbers = ['10', '20', '30', '40']
Attempts:
2 left
💡 Hint
You want to convert strings to integers, not to strings or floats.
✗ Incorrect
Using
int converts each string to an integer. Other options either keep strings or convert to float.🧠 Conceptual
expert2:00remaining
Behavior of map() with multiple iterables
What is the output of this code using
map() with two lists?Data Analysis 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
When multiple iterables are passed, map applies the function to pairs of elements.
✗ Incorrect
The lambda adds elements from both lists pairwise: 1+4=5, 2+5=7, 3+6=9.