ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import heapq
print(heapq.nsmallest(0, [5, 1]), max([], default=-1), min([3, 1, 2], key=lambda x: -x))
  1. A. [5] -1 1
  2. B. [] None 3
  3. C. [] -1 1
  4. D. [] -1 3

Correct answer: D. [] -1 3

nsmallest(0, ...) returns an empty list. max over an empty iterable returns the default -1. min with key=-x picks the element with the smallest negated value, which is the largest element, 3.

More Python Programming questions

Exams that ask this topic