ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import bisect a = sorted(['10', '9', '100', '20']) print(a, bisect.bisect_left(a, '9'), [int(x) for x in a])
- A. ['9', '10', '20', '100'] 1 [9, 10, 20, 100]
- B. ['10', '100', '20', '9'] 3 [10, 100, 20, 9]
- C. ['10', '100', '20', '9'] 2 [10, 100, 20, 9]
- D. ['10', '9', '20', '100'] 3 [10, 9, 20, 100]
Correct answer: B. ['10', '100', '20', '9'] 3 [10, 100, 20, 9]
Strings sort character by character, so '10' < '100' < '20' < '9'. bisect_left('9') returns index 3, and the integers keep the string order.
More Python Programming questions
- What is printed? python def arrows(p): p = sorted(p, key=lambda x: x[1]) cnt = 0 end = None for s, e in p: if end is None or s > end: cnt…
- What is printed? python from functools import cmptokey def largest(nums): s = [str(x) for x in nums] s.sort(key=cmptokey(lambda a, b: -1…
- What is printed? python from itertools import islice, count, takewhile sq = (i i for i in count(1)) print(list(islice(sq, 3))…
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def get(n): return [n] 2 a = get(3) a.append(99) b = get(3)…
- What is printed? python from collections import Counter a = Counter('aabbbc') b = Counter('abbd') print(a - b, (a + b)['b'], sorted((a &…
- What is printed? python print(pow(2, 100, 97), 2 100 % 97, (-2) 3 % 5, pow(-2, 3, 5))