Python Multiple
Choice
Questions
What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3]))
A. [1|x for x in [1, 2, 3]]
B. [-1**x for x in [1, 2, 3]]
C. [x**-1 for x in [1, 2, 3]]
D. [x^-1 for x in range(4)]
Correct Answer: C
Explanation: The output of the function list(map(lambda x:x**-1, [1, 2, 3])) is [1.0, 0.5, 0.3333333333333333] and that of the list comprehension [x**-1 for x in [1, 2, 3]] is [1.0, 0.5, 0.3333333333333333]. Hence the answer is: [x**-1 for x in [1, 2, 3]].