ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(max(range(5), key=lambda x: -abs(x - 2)), min(range(5), key=lambda x: abs(x - 2)))
- A. 2 2
- B. 0 4
- C. 2 0
- D. 4 4
Correct answer: A. 2 2
-abs(x - 2) is largest at x = 2, and abs(x - 2) is smallest at x = 2 as well.
More Python Programming questions
- What is printed? python print(sum(divmod(17, 5)), divmod(-17, 5)[1], 17 % 5 - (-17) % 5)
- What is printed? python def prodexcept(a): n = len(a) out = [1] n left = 1 for i in range(n): out[i] = left left = a[i] right = 1 for i in…
- What is printed? python import bisect def span(a, x): lo = bisect.bisectleft(a, x) if lo == len(a) or a[lo] != x: return (-1, -1) return…
- What is printed? python def palsub(s): n = len(s) best = '' for c in range(2 n - 1): l, r = c // 2, c // 2 + c % 2 while l >= 0 and r < n…
- What is printed? python def partition(s): last = {ch: i for i, ch in enumerate(s)} out = [] start = end = 0 for i, ch in enumerate(s): end…
- What is printed? python def units(boxes, cap): boxes = sorted(boxes, key=lambda b: -b[1]) total = 0 for n, u in boxes: take = min(n, cap)…