All quizzesEasy
map, filter & reduce — Series 2
Preview — 3 of 10 questions
What is the output of the following code?
javascript
a = [1, 2, 3]
b = [10, 20, 30, 40]
result = list(map(lambda x, y: x + y, a, b))
print(result)A[11, 22, 33]
B[11, 22, 33, 40]
CTypeError: <lambda>() missing 1 required positional argument
D[[1, 10], [2, 20], [3, 30], [None, 40]]
What is the output of the following code?
javascript
values = [0, 1, "", "hello", None, [], [1, 2], False, 42]
result = list(filter(None, values))
print(result)A[0, 1, '', 'hello', None, [], [1, 2], False, 42] — filter(None, ...) passes every element through unchanged.
B[1, 'hello', [1, 2], 42]
C[0, '', None, [], False]
DTypeError: 'NoneType' object is not callable
What is the output of the following code?
javascript
nums = [-3, -1, 0, 2, 5]
clamped = [n if n > 0 else 0 for n in nums]
print(clamped)A[-3, -1, 0, 2, 5]
B[0, 0, 0, 0, 0]
C[0, 0, 0, 2, 5]
DTypeError: invalid syntax — a conditional expression cannot appear before the for clause in a comprehension.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.