Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.