question 66 Lists & Tuples · medium
The catalogue lost its order
This program should print a film site's top 3 films by rating, then every title again in its original catalogue order. Each film is a (rating, title) tuple, and sorting tuples compares their first items, the ratings. The output has two bugs: the top list skips the best film, and the catalogue comes out in rating order. Fix the program.
Input
films, a list of (rating, title) tuples with different ratingsPrints
Top 3:, then up to three lines <title> <rating> from highest to lowest, then Catalogue: and every title in the original orderExamplesthe starter's films →
Night Harbor 4.6, Glass Echo of Glass 4.1, Wild Archive 3.9, then the catalogue in its original orderExpected output9 lines
- 1Top 3:
- 2Night Harbor 4.6
- 3Glass Echo of Glass 4.1
- 4Wild Archive 3.9
- 5Catalogue:
- 6Wild Archive
- 7Night Harbor
- 8Up
- 9Glass Echo of Glass