ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import Counter
c = Counter('abracadabra')
print(sum(v for v in c.values() if v % 2), len(c), c.total())- A. 2 5 10
- B. 7 5 11
- C. 3 5 11
- D. 7 6 11
Correct answer: B. 7 5 11
Counts are a:5, b:2, r:2, c:1 and d:1. sum adds the odd counts themselves, 5 + 1 + 1 = 7. There are five distinct letters, and total() gives 11.
More Python Programming questions
- What is printed? python x = 0b1010 y = 0o17 z = 0xFF print(x ^ y, x | z, z >> 4, y & ~x)
- What is printed? python a = 'Python' print(a[::-1][1:4], a[-2:] + a[:2], a.upper()[::2])
- What is printed? python n = 10 6 s = 0 i = 1 while i <= n: s += n // i i = 10 print(s)
- What is printed? python def matmul(A, B, m): return [[sum(A[i][k] B[k][j] for k in range(2)) % m for j in range(2)] for i in range(2)] def…
- What is printed? python n = 12 print(n & 1 == 0, (n & 1) == 0, n & n - 1 == 0, 8 & 7 == 0)
- What is printed on the first line? python print(pow(2, -1, 5), pow(3, -1, 7), pow(2, -3, 9)) try: print(pow(2, -1, 4)) except ValueError…