ProgrammingHardTCS NQT · Infosys

What is printed?

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

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

Counts are i=4, s=4, p=2 and m=1. most_common keeps tied items in the order they were first seen, so i (seen before s) comes before s, and the top three are i, s and p.

More Python Programming questions

Exams that ask this topic