ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import bisect print(bisect.bisect_left([5, 4, 3], 4))
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: D. 0
bisect assumes ascending order. On the descending list [5, 4, 3] the probes see 4 < 4 as False and move the upper bound left, so it returns 0 instead of the answer a sorted list would give.
More Python Programming questions
- What is printed? python import bisect print(bisect.bisectleft([(1, 'a'), (3, 'b'), (5, 'c')], 3, key=lambda t: t[0]))
- What is printed? python import bisect a = [(1, 'x'), (4, 'y')] bisect.insort(a, (3, 'z'), key=lambda t: t[0]) print(a)
- What is printed? python import heapq h = [1, 3, 5] r = heapq.heapreplace(h, 0) print(r, sorted(h))
- What is printed? python import heapq h = [1, 3, 5] r = heapq.heappushpop(h, 0) print(r, sorted(h))
- What is printed? python import heapq h = [] try: heapq.heappush(h, (1, {'a': 1})) heapq.heappush(h, (1, {'b': 2})) except TypeError as e…
- What is printed? python import heapq print(heapq.nlargest(2, ['pear', 'fig', 'apple'], key=len))