Leeds, leeds, LEEDS

Data with PythonEasy+10 XP+10

Leeds, leeds, LEEDS

A charity asked supporters to type their town into a box. The same town comes back as "Leeds", " leeds", "LEEDS " and so on.

Task: write count_town(towns, town).

  • towns is a list of what people typed. town is a tidy town name with a capital first letter, like "Leeds" or "Milton Keynes".
  • Clean every entry in towns: remove spaces from both ends, then capitalise the first letter of each word and make the rest lowercase.
  • Return how many cleaned entries are exactly town, as a whole number.

There is always at least one entry in towns.

Examples

towns = ["Leeds", " leeds", "LEEDS ", "York", "york"]
town = "Leeds"
returns 3
towns = ["Leeds", " leeds", "LEEDS ", "York", "york"]
town = "Bath"
returns 0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run