ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import heapq h = [(2, 'x'), (1, 'y'), (1, 'a')] heapq.heapify(h) heapq.heappush(h, (0, 'z')) print(heapq.heappop(h), heapq.heappop(h))
- A. (0, 'z') (1, 'y')
- B. (1, 'a') (0, 'z')
- C. (1, 'y') (1, 'a')
- D. (0, 'z') (1, 'a')
Correct answer: D. (0, 'z') (1, 'a')
After heapify and the push, the smallest tuple is (0, 'z'). The next smallest is (1, 'a'), since 'a' sorts before 'y' when the first fields tie.
More Python Programming questions
- What is printed? python s = 'hello world' print(s.title(), s.swapcase()[:5], s.replace('l', '', 2))
- What is printed? python a = [[0] 2 for in range(2)] b = [[0] 2] 2 a[0][1] = 5 b[0][1] = 5 print(a, b)
- What is printed? python print(divmod(7, 2), divmod(-7, 2), divmod(7.5, 2))
- What is printed? python def outer(): res = [] for i in range(3): res.append(lambda: i) return [f() for f in res] def outer2(): return…
- What is printed? python print(10 18 % 7, (10 18 + 2) // 4, -(2 63) // (2 62))
- What is printed? python lst = list(range(5)) lst[1:4] = [] try: lst[::2] = [9, 9] except ValueError: print('ValueError', lst)