Challenge

Past

One concept, three rungs. Reaching rung 1 is the goal, so climb as far as you can.

Counting Colours

loops + counting matches

Rung 1Daily goal5 points

Count the red ones

Write a function called count_red

You get a list of colour words. Return how many of them are "red". An empty list has 0 red ones.

Examples

InputOutput
["red", "blue", "red"]2
[]0
["blue"]0
["red"]1

There are extra hidden tests, so make it work in general, not just for these.

Rung 2Bonus7 points

Count any colour

Write a function called count_color

Now the colour you are looking for is given to you as a second argument. Return how many times it appears in the list. If it never appears, return 0.

Examples

InputOutput
["red", "blue", "red"], "blue"1
["red", "blue"], "green"0
[], "red"0
["cat", "cat", "cat"], "cat"3

There are extra hidden tests, so make it work in general, not just for these.

Rung 3Bonus10 points

The most popular colour

Write a function called most_common_color

Return the colour that appears the most times. If two colours appear the same number of times, return the one that comes first in the list. An empty list returns None.

Examples

InputOutput
["red", "blue", "red"]"red"
[]None
["blue"]"blue"
["red", "blue"]"red"

There are extra hidden tests, so make it work in general, not just for these.

Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.