ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: D. [('i', 4), ('s', 4)] ('m', 1)

most_common keeps the first-inserted letter first when counts tie, so i (seen before s) comes first. sorted is stable, so the smallest count with the earliest insertion is m.

More Python Programming questions

Exams that ask this topic