Predict the output
What does this print?
from collections import Counter
c = Counter("mississippi")
print(c.most_common(2))Choose an answer, then open Show answer below to check it.
Show answer
Answer: A [('i', 4), ('s', 4)]
Right: i and s both appear 4 times, and i was seen first.
Equal counts keep the order items were first counted, which is why 'i' (index 1) leads 's' (index 2).
Why not the others?
- B [('s', 4), ('i', 4)]. Ties keep first-seen order, and i comes before s in the word.
- C [('s', 4), ('p', 2)]. i also appears 4 times, more than p.