def albums_by_decade(formatter, albums):
    """Returns the rated albums sorted by decreasing decade and rating."""
    decades = set([album["decade"] for album in albums])
    sorted_albums = {}
    for decade in sorted(decades, reverse=True):
        sorted_albums[decade] = sorted(
            [x for x in albums if x["decade"] == decade],
            key=lambda x: x["rating"],
            reverse=True,
        )
    return formatter.parse_categorised_lists(
        sorted_albums, formatter.format_header, formatter.format_album
    )