ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from collections import Counter
print(Counter('abracadabra').most_common(3))
  1. A. [('a', 5), ('b', 2), ('r', 2)]
  2. B. [('a', 5), ('r', 2), ('b', 2)]
  3. C. [('a', 5), ('b', 2), ('c', 1)]
  4. D. [('a', 5), ('r', 2), ('c', 1)]

Correct answer: A. [('a', 5), ('b', 2), ('r', 2)]

most_common sorts by count and keeps insertion order for ties. In 'abracadabra', b is first seen before r, so the two-count ties appear as b then r.

More Python Programming questions

Exams that ask this topic