One Island, Three Answers

Data with PythonHard+10 XP+10

One Island, Three Answers

A field researcher wants a short report on one island of a penguin survey.

Task: write island_report(penguins, island) that returns a list of three answers about the penguins on island:

  1. how many penguins were measured there
  2. their average mass_g, rounded to 1 decimal place
  3. the species of the heaviest penguin there

penguins is a list of dictionaries, each with species, island and mass_g. Island names must match exactly, capitals included.

If no penguins were measured on island, return [0, 0.0, ""].

No two penguins on the same island share the same mass.

Examples

penguins = [{"species": "Adelie", "island": "Dream", "mass_g": 3700}, {"species": "Gentoo", "island": "Biscoe", "mass_g": 5400}, {"species": "Chinstrap", "island": "Dream", "mass_g": 3950}, {"species": "Adelie", "island": "Biscoe", "mass_g": 3500}, {"species": "Adelie", "island": "Dream", "mass_g": 3425}]
island = "Dream"
returns [3, 3691.7, 'Chinstrap']
penguins = [{"species": "Adelie", "island": "Dream", "mass_g": 3700}, {"species": "Gentoo", "island": "Biscoe", "mass_g": 5400}, {"species": "Chinstrap", "island": "Dream", "mass_g": 3950}, {"species": "Adelie", "island": "Biscoe", "mass_g": 3500}, {"species": "Adelie", "island": "Dream", "mass_g": 3425}]
island = "Biscoe"
returns [2, 4450.0, 'Gentoo']
penguins = [{"species": "Adelie", "island": "Dream", "mass_g": 3700}, {"species": "Gentoo", "island": "Biscoe", "mass_g": 5400}]
island = "Torgersen"
returns [0, 0.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