0
0
Data Analysis Pythondata~20 mins

map() for element-wise mapping in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Map Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[2, 3, 4, 5]
B[1, 4, 9, 16]
C[1, 8, 27, 64]
D[1, 2, 3, 4]
Attempts:
2 left
💡 Hint
Remember, map() applies the function to each element in the list.
data_output
intermediate
2: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)
A['a', 'b', 'c']
B['1', '2', '3']
C['A', 'B', 'C']
D['A', 'B', 'C', 'D']
Attempts:
2 left
💡 Hint
Mapping applies to dictionary keys by default.
🔧 Debug
advanced
2: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)
ANameError: name 'y' is not defined
BTypeError: unsupported operand type(s) for +: 'int' and 'function'
CSyntaxError: invalid syntax
DNo error, output is [2, 3, 4]
Attempts:
2 left
💡 Hint
Check if all variables inside the lambda are defined.
🚀 Application
advanced
2: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']
Alist(map(float, str_numbers))
Blist(map(str, str_numbers))
Clist(map(lambda x: x + 1, str_numbers))
Dlist(map(int, str_numbers))
Attempts:
2 left
💡 Hint
You want to convert strings to integers, not to strings or floats.
🧠 Conceptual
expert
2: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)
A[5, 7, 9]
B[1, 2, 3, 4, 5, 6]
C[4, 10, 18]
DTypeError: <lambda>() missing 1 required positional argument
Attempts:
2 left
💡 Hint
When multiple iterables are passed, map applies the function to pairs of elements.