All quizzesMedium
itertools & partial — Series 3
Preview — 3 of 10 questions
What is the output of the following code?
javascript
from itertools import pairwise
data = [1, 3, 6, 10]
print(list(pairwise(data)))
diffs = [b - a for a, b in pairwise(data)]
print(diffs)A[(1, 3), (3, 6), (6, 10)], [2, 3, 4]
B[(1, 3), (6, 10)], [2, 4]
C[(1, 3), (3, 6), (6, 10), (10, 1)], [2, 3, 4, -9]
D[1, 3, 6, 10], [2, 3, 4]
What is the output of the following code?
javascript
from itertools import repeat
nums = [1, 2, 3, 4]
squared = list(map(pow, nums, repeat(2)))
print(squared)ARecursionError — repeat(2) never stops producing values
B[1, 4, 9, 16]
C[2, 4, 6, 8]
D[1, 2, 3, 4]
What is the output of the following code?
javascript
from functools import reduce
nested = [[1, 2], [3, 4], [5]]
flat = reduce(lambda acc, lst: acc + lst, nested, [])
print(flat)A[1, 2, [3, 4], [5]]
BTypeError: can only concatenate list (not "list") to list
C[1, 2, 3, 4, 5]
D[[1, 2], [3, 4], [5]]
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.