ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from functools import lru_cache
@lru_cache(maxsize=None)
def f(a, b=0):
return a + b
f(1, 2)
f(1, b=2)
f(1)
print(f.cache_info().misses, f.cache_info().hits)- A. 2 1
- B. 2 0
- C. 3 0
- D. 1 2
Correct answer: C. 3 0
lru_cache keys on the exact call form, so f(1, 2), f(1, b=2) and f(1) are three different keys. Each one is a miss and none repeats, so there are no hits.
More Python Programming questions
- What is printed? python from collections import OrderedDict od = OrderedDict() for k in ['a', 'b', 'c']: od[k] = ord(k) od.movetoend('a')…
- What is printed? python b = [3, 1, 2] a = b.sort() c = sorted(b, reverse=True) print(a, b, c)
- 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…