ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
b = [3, 1, 2] a = b.sort() c = sorted(b, reverse=True) print(a, b, c)
- A. [1, 2, 3] [1, 2, 3] [3, 2, 1]
- B. None [3, 1, 2] [3, 2, 1]
- C. None [1, 2, 3] [3, 2, 1]
- D. [1, 2, 3] None [3, 2, 1]
Correct answer: C. None [1, 2, 3] [3, 2, 1]
list.sort sorts in place and returns None, so a is None. sorted returns a new list, and reverse=True gives the descending copy.
More Python Programming questions
- What is printed? python def kadane(a): best = cur = a[0] start = bestl = bestr = 0 for i in range(1, len(a)): if cur < 0: cur = a[i] start…
- What is printed? python def threesum(a): a = sorted(a) out = [] for i in range(len(a) - 2): if i and a[i] == a[i - 1]: continue l, r = i +…
- What is printed? python def distinct(s, t): dp = [1] + [0] len(t) for ch in s: for j in range(len(t), 0, -1): if t[j - 1] == ch: dp[j] +=…
- What is printed? python import bisect def pairsle(a, d): a = sorted(a) c = 0 for i, x in enumerate(a): j = bisect.bisectright(a, x + d, i…
- What is printed? python import bisect def closest(a, x): i = bisect.bisectleft(a, x) cands = a[max(i - 1, 0):i + 1] return min(cands…
- What is printed? python def content(g, s): g.sort(); s.sort() i = j = 0 while i < len(g) and j < len(s): if s[j] >= g[i]: i += 1 j += 1…