

Comprehension Sorter
Write a function filter_stars(stars, min_mag) that takes a list of dictionaries representing stars, e.g. [{"name": "Sirius", "mag": -1.46}], and a float min_mag. It should return a dictionary mapping star names to their magnitudes, but only for stars with a magnitude strictly greater than min_mag (lower brightness). Use a dictionary comprehension.
Examples
filter_stars([{'name': 'Sirius', 'mag': -1.46}, {'name': 'Vega', 'mag': 0.03}], -1)
→ {'Vega': 0.03}
filter_stars([{'name': 'Sirius', 'mag': -1.46}], 0)
→ {}
solution.py
PYTHON
Saved as you type
Tests
0 of 4 passing- •filter brightnessfilter_stars([{'name': 'Sirius', 'mag': -1.46}, {'name': 'Vega', 'mag': 0.03}], -1)expected {'Vega': 0.03}
- •filter allfilter_stars([{'name': 'Sirius', 'mag': -1.46}], 0)expected {}
- •empty listfilter_stars([], 0)expected {}
- •all dimmerfilter_stars([{'name': 'Deneb', 'mag': 1.25}, {'name': 'Polaris', 'mag': 1.97}], 1)expected {'Deneb': 1.25, 'Polaris': 1.97}
On the line
+50 XP
Pass all 4 tests to claim it.
