ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
import itertools print(sum(b - a for a, b in itertools.pairwise([1, 4, 2, 8])))
- A. 7
- B. 11
- C. 13
- D. 5
Correct answer: A. 7
The adjacent differences telescope to the last element minus the first, which is 8 - 1 = 7. That is smaller than the sum of absolute differences, which is 11.
More Python Programming questions
- What is printed? python g = [[0] 3] 2 g[0][1] = 5 h = [[0] 3 for in range(2)] h[0][1] = 5 print(g, h)
- What is printed? python import heapq h = [] for w, name in [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'c')]: heapq.heappush(h, (w, name)) out = []…
- What is printed? python recs = [('a', 2), ('b', 1), ('c', 2), ('d', 1)] print([n for n, v in sorted(recs, key=lambda r: r[1]…
- What is printed? python pairs = list(zip([1, 2, 3], 'ab', [True])) print(pairs, len(list(zip())))
- What is printed? python def threeless(a, t): a = sorted(a) n = len(a) c = 0 for i in range(n - 2): l, r = i + 1, n - 1 while l < r: if…
- What is printed? python import heapq def rooms(iv): iv = sorted(iv) h = [] for s, e in iv: if h and h[0] <= s: heapq.heapreplace(h, e)…