ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
def f(xs):
xs.sort()
return xs
data = [3, 1, 2]
res = f(data)
print(data is res, data)- A. True [3, 1, 2]
- B. False [3, 1, 2]
- C. True [1, 2, 3]
- D. False [1, 2, 3]
Correct answer: C. True [1, 2, 3]
sort() works in place and f returns the same list object. The caller's list is changed, so data is res holds and data shows the sorted order.
More Python Programming questions
- Which Python construct is the most efficient way to test whether a sorted list a contains x in O(log n) time without building extra…
- Which of the following problems can be solved correctly by a greedy algorithm that sorts by end time, when given the intervals and asked…
- What is printed? python a = [1, 2, 3, 4, 5, 6] print(a[1::2], a[::-2], a[4:1:-1])
- What is printed? python s = 'a1b22c333' import re print(re.findall(r'd+', s), sum(int(x) for x in re.findall(r'd+', s)))
- What is printed? python def solve(n, memo={}): if n in memo: return memo[n] if n < 2: return n memo[n] = solve(n - 1) + solve(n - 2)…
- What is printed? python x = 7 match x: case 1 | 2: r = 'small' case int(v) if v > 5: r = f'big{v}' case : r = 'other' print(r)