ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
print(len(set(map(lambda x: x % 3, range(10)))), sum(1 for _ in filter(None, [0, 1, '', 'a', None])))
- A. 2 2
- B. 3 3
- C. 3 2
- D. 2 3
Correct answer: C. 3 2
The residues of 0 to 9 modulo 3 are only 0, 1 and 2. filter(None, ...) keeps only truthy items, so 0, '' and None are dropped.
More Python Programming questions
- What is printed? python def mpow(b, e, m): r = 1 b %= m while e: if e & 1: r = r b % m b = b b % m e >>= 1 return r print(mpow(2, 10…
- What is printed? python import math n = 1016 - 1 print(math.isqrt(n), int(n 0.5))
- What is printed? python print(sorted([('b', 2), ('a', 2), ('c', 3)], key=lambda t: (-t[1], t[0])))
- What is printed? python def ok(s): def chk(l, r): while l < r: if s[l] != s[r]: return False l += 1 r -= 1 return True l, r = 0, len(s)…
- What is printed? python def removek(num, k): st = [] for d in num: while k and st and st[-1] > d: st.pop() k -= 1 st.append(d) st =…
- What is printed? python def divcount(a, k): cnt = {0: 1} s = 0 ans = 0 for x in a: s = (s + x) % k ans += cnt.get(s, 0) cnt[s] =…