ProgrammingVery hardTCS NQT · Wipro pattern
What is printed?
What is printed?
from functools import lru_cache
class C:
@lru_cache(maxsize=None)
def f(self, x):
return x * 2
a, b = C(), C()
a.f(1)
b.f(1)
print(C.f.cache_info().misses, a.f(1) == b.f(1))- A. 1 True
- B. 2 False
- C. 2 True
- D. 0 True
Correct answer: C. 2 True
The cache key includes self, and each instance is a different key, so each call misses once. Later calls with the same instance and argument hit the cache.
More Python Programming questions
- What is printed? python class A: def init(self, v): self.v = v def eq(self, o): return isinstance(o, A) and self.v == o.v xs = [A(1)…
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b)
- What is printed? python nums = [10, 9, 100, 1] print(sorted(nums, key=str), max(nums, key=str), sorted(map(str, nums))[-1])
- What is printed? python def ngecirc(a): n = len(a) res = [-1] n st = [] for i in range(2 n): x = a[i % n] while st and a[st[-1]] < x…
- What is printed? python def dsum(n): return n if n < 10 else dsum(sum(map(int, str(n)))) print(dsum(9875), dsum(0), dsum(999999999999))
- What is printed? python def lcp(words): out = [] for col in zip(words): if len(set(col)) == 1: out.append(col[0]) else: break return…