ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import heapq h = [4, 1, 3] heapq.heapify(h) print(h[0], sorted(h))
- A. 1 [1, 3, 4]
- B. 4 [1, 3, 4]
- C. 1 [4, 3, 1]
- D. 3 [1, 3, 4]
Correct answer: A. 1 [1, 3, 4]
heapify puts the minimum at index 0. The list order is a heap, not a sorted list, but sorted(h) still shows all three values in ascending order.
More Python Programming questions
- What is printed? python from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=3) d.append(6) d.appendleft(0) print(list(d))
- What is printed? python x = [0] 3 y = [[0] 2] 2 y[0][1] = 7 print(x, y)
- What is printed? python import bisect vals = [10, 20, 30] print(bisect.bisectleft(vals, 0), bisect.bisectleft(vals, 35)…
- What is printed? python from collections import deque d = deque('abcde') d.rotate(2) print(''.join(d), ''.join(deque('abcde').reversed()))
- What is printed? python print(int('0' 5 + '7') + int(' -3 '), len(str(int('9' 50) + 1)))
- What is printed? python import math print(math.isqrt(99), math.isqrt(100), round(2.5), round(3.5))