Lists and dictionaries

Count the occurrences of moss in each list.

Examples

Example 1

Input
["moss", "fern", "moss"]
Expected output
2

Example 2

Input
["fern"]
Expected output
0

Hints and solution

Hint 1

Increment only when the current item equals "moss".

Reveal worked answer

Use counts.get("moss", 0) to read the result so an input without moss produces zero.

Back to the lesson