ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import bisect a = sorted([5, 1, 9, 3, 7]) print(bisect.bisect_right(a, 7) - bisect.bisect_left(a, 4))
- A. 1
- B. 0
- C. 2
- D. 3
Correct answer: C. 2
After sorting, a is [1, 3, 5, 7, 9]. bisect_right(a, 7) is 4 and bisect_left(a, 4) is 2, so the count of values in [4, 7] is 2, which is the count of the values 5 and 7.
More Python Programming questions
- What is printed? python from collections import defaultdict d = defaultdict(list) d['a'] print('a' in d, len(d), d.get('b'), 'b' in d)
- What is printed? python from functools import cache @cache def paths(r, c): return 1 if r == 0 or c == 0 else paths(r - 1, c) + paths(r, c…
- What is printed? python print(sum(map(int, str(2 100))))
- What is printed? python print(bin(12345).count('1'), len(bin(12345)) - 2)
- What is printed? python print(int(float('1e3')), int('12'))
- What is printed? python print('%5.2f|%-4d|%04x' % (3.14159, 7, 255))