ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from functools import lru_cache
@lru_cache(None)
def total(xs):
return sum(xs)
try:
print(total([1, 2, 3]))
except TypeError as e:
print(e)- A. unhashable type: 'list'
- B. 6
- C. TypeError
- D. None
Correct answer: A. unhashable type: 'list'
lru_cache builds a dictionary key from the arguments, so each argument must be hashable. A list is not hashable, so the call fails with TypeError before the function runs. Passing a tuple would work.
More Python Programming questions
- What is printed? python import bisect print(bisect.bisectleft(range(100), True, key=lambda x: x x >= 50))
- What is printed? python n = 30 s = [True] (n + 1) s[0] = s[1] = False for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] = [False]…
- What is printed? python print(-0.0 == 0.0, str(-0.0), repr(0.0 -1))
- What is printed? python print(float('1000.5'), end=' ') try: int('10') except ValueError: print('VE')
- What is printed? python d = {1: 1} try: for k in d: d[k + 1] = 0 except RuntimeError as e: print(e)
- What is printed? python print([sum(i for i in range(3) if m >> i & 1) for m in range(8)])