What does collections.Counter(“banana”) evaluate to?
Correct answer B. 3
Explanation
Counter is a dict subclass that counts hashable items, so Counter("banana") counts each letter, giving a: 3, n: 2 and b: 1. Looking up a missing key in a Counter returns 0 instead of raising KeyError, which makes it convenient for tallying.
Answer checked How we write and check questions
Discussion