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())
  1. A. 2 5 10
  2. B. 7 5 11
  3. C. 3 5 11
  4. 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

Exams that ask this topic