from typing import Iterator from simfile.types import Chart # Imperative version def charts_for_stepstype(charts, stepstype="dance-single") -> Iterator[Chart]: for chart in charts: if chart.stepstype == stepstype: yield chart # One-liner version def charts_for_stepstype(charts, stepstype="dance-single") -> Iterator[Chart]: yield from filter(lambda chart: chart.stepstype == stepstype, charts)