ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from collections import Counter
print(Counter('hello').most_common(2))
  1. A. [('l', 2), ('o', 1)]
  2. B. [('l', 2), ('h', 1)]
  3. C. [('l', 2), ('e', 1)]
  4. D. [('h', 1), ('l', 2)]

Correct answer: B. [('l', 2), ('h', 1)]

Counter('hello') gives l:2, h:1, e:1, o:1. The most common value is l with 2. Ties among the count-1 letters go to the one seen first, which is h.

More Python Programming questions

Exams that ask this topic