ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from collections import Counter
c = Counter([3, 1, 3, 2, 1, 3])
print(c.most_common(1), sorted(c.elements()), c[7])
  1. A. [(3, 3)] [1, 1, 2, 3, 3] 0
  2. B. [(1, 2)] [1, 1, 2, 3, 3, 3] 0
  3. C. [(3, 3)] [1, 1, 2, 3, 3, 3] None
  4. D. [(3, 3)] [1, 1, 2, 3, 3, 3] 0

Correct answer: D. [(3, 3)] [1, 1, 2, 3, 3, 3] 0

Counter returns 0 for a missing key instead of raising KeyError, and most_common(1) gives the single most frequent value 3 with count 3. elements() repeats each value by its count, so sorting gives six items.

More Python Programming questions

Exams that ask this topic