ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
import bisect a = [9, 7, 5, 3, 1] print(bisect.bisect_left(a, -6, key=lambda v: -v), bisect.bisect_left(a, 6, key=lambda v: -v))
- A. 2 5
- B. 3 2
- C. 2 3
- D. 5 2
Correct answer: A. 2 5
The key function is applied to the list items only, not to x, so the target must be in key space. bisect_left(a, -6) gives index 2, while passing 6 compares it with the negated keys and gives 5.
More Python Programming questions
- What is printed? python from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=5) d.rotate(2) d.appendleft(0) print(list(d)…
- What is printed? python print(max(['bb', 'aa', 'c'], key=len), min(['bb', 'aa', 'c'], key=len))
- What is printed? python from collections import defaultdict words = ['eat', 'tea', 'tan', 'ate', 'nat', 'bat'] g = defaultdict(list) for w…
- What is printed? python print(' a b '.split(' '), ' a b '.split(), 'a b x c d'.split(None, 1))
- What is printed? python from fractions import Fraction x = Fraction(1, 3) + Fraction(1, 6) print(x, x.numerator, Fraction(6, -8))
- What is printed? python print(format(255, '08b'), format(255, '#x'), '{:>5}|{:<3}|'.format(42, 7))