ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
import bisect a = [10, 20, 20, 30] print([bisect.bisect_left(a, x) for x in (20, 25, 5, 40)])
- A. [1, 2, 0, 4]
- B. [1, 3, 0, 4]
- C. [2, 3, 0, 4]
- D. [1, 3, 0, 3]
Correct answer: B. [1, 3, 0, 4]
bisect_left returns the first index where the value fits, so for 20 it is the first of the two equal values. 25 goes before 30 at index 3, and 40 goes at the end, index 4.
More Python Programming questions
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def grid(r, c): if r == 0 or c == 0: return 1 return grid(r…
- What is printed? python def cancomplete(gas, cost): total = tank = start = 0 for i in range(len(gas)): d = gas[i] - cost[i] total += d…
- What is printed? python x = 0b101100 print(x & (x - 1), x & -x, bin(x).count('1'))
- What is printed? python M = 1000000007 print(pow(2, -1, 7), pow(3, 4, 5), (pow(10, 9, M) 2) % M)
- What is printed? python import math print(math.comb(10, 3), math.gcd(12, 18, 24), math.lcm(4, 6, 10))
- What is printed? python import itertools print(sum(b - a for a, b in itertools.pairwise([1, 4, 2, 8])))