ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import bisect vals = [10, 20, 30] print(bisect.bisect_left(vals, 0), bisect.bisect_left(vals, 35), bisect.bisect_left(vals, 20))
- A. 1 3 1
- B. 0 2 1
- C. 0 3 2
- D. 0 3 1
Correct answer: D. 0 3 1
A value below every element goes to index 0 and a value above all elements goes to len(vals), which is 3. bisect_left places 20 at index 1, before the existing 20.
More Python Programming questions
- 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))
- What is printed? python import itertools print(list(itertools.accumulate([3, 1, 4, 1, 5], max))[-1], list(itertools.accumulate([3, 1, 4]…
- What is printed? python import heapq print(heapq.heappop([]) if False else 'ok', heapq.nlargest(1, []))
- 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…