ProgrammingVery hardTCS NQT · Wipro pattern
What is printed?
What is printed?
from functools import lru_cache
@lru_cache(maxsize=None)
def get(n):
return [n] * 2
a = get(3)
a.append(99)
b = get(3)
print(a, b, a is b)- A. [3, 3, 99] [3, 3, 99] True
- B. [3, 3, 99] [3, 3] False
- C. [3, 3] [3, 3] False
- D. [3, 3, 99] [3, 3] True
Correct answer: A. [3, 3, 99] [3, 3, 99] True
lru_cache returns the same cached list object each time, so mutating a changes what later calls return. Cached results are shared, not copied.
More Python Programming questions
- 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))
- What is printed? python from itertools import permutations, combinations print(len(list(permutations('abcd', 2)))…
- What is printed? python def sqsorted(a): l, r = 0, len(a) - 1 out = [0] len(a) k = len(a) - 1 while l <= r: if abs(a[l]) > abs(a[r])…
- What is printed? python def minpath(g): dp = [0] len(g[0]) for i, row in enumerate(g): for j, v in enumerate(row): if i == 0 and j == 0…
- What is printed? python from functools import lrucache def wb(s, words): @lrucache(maxsize=None) def go(i): if i == len(s): return 1…