ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
from collections import Counter
c = Counter('mississippi')
print(c.most_common(2))
  1. A. [('i', 4), ('s', 4)]
  2. B. [('s', 4), ('i', 4)]
  3. C. [('i', 4), ('p', 2)]
  4. D. [('i', 4), ('m', 1)]

Correct answer: A. [('i', 4), ('s', 4)]

Counter keeps first-seen order for ties, and i appears before s in mississippi, so most_common(2) lists i first.

More Python Programming questions

Exams that ask this topic