ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import heapq print(heapq.heappop([]) if False else 'ok', heapq.nlargest(1, []))
- A. ok []
- B. ok None
- C. IndexError
- D. []
Correct answer: A. ok []
The first expression is never evaluated, so the program never calls heappop on an empty list. nlargest(1, []) returns an empty list rather than None or an error.
More Python Programming questions
- What is the time complexity of building a heap from n items with heapq.heapify, compared with pushing the n items one by one with…
- What is printed? python x = 255 print(x.bitlength(), bin(x).count('1'), (x & -x), (x - 1) & x)
- What is printed? python print(-7 // 2, 7 // -2, -7 % 2, 7 % -2)
- What is printed? python def pairs(a, t): a = sorted(a) i, j, c = 0, len(a) - 1, 0 while i < j: s = a[i] + a[j] if s == t: c += 1 i += 1 j…
- What is printed? python def countk(a, k): pre = {0: 1} s = 0 ans = 0 for x in a: s += x ans += pre.get(s - k, 0) pre[s] = pre.get(s, 0) +…
- What is printed? python from collections import deque g = ['..#', '.##', '...'] def bfs(g): R, C = len(g), len(g[0]) d = {(0, 0): 0} q =…