ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
from bisect import bisect_left, bisect_right a = [1, 2, 2, 2, 3] print(bisect_left(a, 2), bisect_right(a, 2), bisect_left(a, 0), bisect_right(a, 4))
- A. 1 3 0 5
- B. 1 4 0 5
- C. 1 4 0 4
- D. 0 4 0 5
Correct answer: B. 1 4 0 5
bisect_left gives the first index where 2 can go, which is 1, and bisect_right gives the position after the last 2, which is 4. Values past the end insert at the length of the list.
More Python Programming questions
- What is printed? python print(str(12345)[::-1], int(str(12345)[::-1]) + 1, sum(int(d) for d in str(12345)), len(str(0)))
- What is printed? python print(0o777 ^ 0o070, 0b1111 & 0xF0 | 0x0F, 1000000 // 1e3)
- What is printed? python s = 'Straße' print(s.upper(), s.lower(), s.casefold() == 'strasse', len(s.upper()))
- What is printed? python print(0.1 0.1 == 0.01, 0.1 0.1, round(0.1 0.1, 2) == 0.01)
- What is printed? python print(int(3.99999999999999999), int(-3.7), 3.99999999999999999 == 4.0, 3)
- What is printed? python s = 'x' 3 print(s -1 == '', s.replace('x', 'xy', 2), s.count('xx'), s.index('x', 1))