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))
- A. [5] -1 1
- B. [] None 3
- C. [] -1 1
- 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
- What is printed? python print(pow(2, -1, 10 9 + 7))
- What is printed? python import math n = 10 30 - 1 print(math.isqrt(n), int(n 0.5))
- What is printed? python print(2 53 + 1 == float(2 53 + 1))
- What is printed? python import io s = io.StringIO("abcn") print(repr(s.readline()), repr(s.readline()))
- What is printed? python data = "2n10 20n30n" it = iter(data.split()) n = int(next(it)) arr = [int(next(it)) for in range(n)] print(arr…
- What is printed? python from operator import itemgetter rows = [('b', 2, 'x'), ('a', 2, 'y'), ('c', 1, 'z')] print([r[0] for r in…