ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import heapq
h = []
for x in [5, 1, 3]:
heapq.heappush(h, x)
heapq.heappush(h, 0)
print([heapq.heappop(h) for _ in range(2)], len(h))- A. [1, 3] 2
- B. [0, 3] 2
- C. [0, 1] 2
- D. [0, 1] 3
Correct answer: C. [0, 1] 2
Two pops return the two smallest values, 0 and 1. Four items were pushed and two were removed, so two remain.
More Python Programming questions
- What is printed? python s = 'hello' print(s.index('l'), s.rfind('l'), s.find('l', 3), s.index('lo'))
- What is printed? python import itertools print(sum(1 for in itertools.combinations(range(6), 2)), sum(1 for in…
- Which of the following statements about Python's sort is correct for CP problems?
- What is printed? python def solve(n): if n == 0: return [] return solve(n // 2) + [n % 2] print(solve(6), solve(0))
- What is printed? python print(divmod(7, -3), 7 % -3, -7 % 3, -7 // 3)
- What is printed? python x = 'aaa' y = list(x) y[0] = 'b' print(x, ''.join(y), x is y)