What is the output of the following Python code snippet?
import heapq
print(heapq.nlargest(2, [1, 3, 2]))
print(heapq.nlargest(2, [1, 3, 2]))
Correct answer
D. [3, 2]
D. [3, 2]
heapq.nlargest returns the n largest elements in descending order.
Asked in: Python Interview Standard Library
https://docs.python.org/3/library/index.htmlNot sure why the answer is D? Ask here and get an explanation.