runtime
66 / 500
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.

Inputfilms, a list of (rating, title) tuples with different ratings
PrintsTop 3:, then up to three lines <title> <rating> from highest to lowest, then Catalogue: and every title in the original order
Examplesthe starter's films → Night Harbor 4.6, Glass Echo of Glass 4.1, Wild Archive 3.9, then the catalogue in its original order
Expected output9 lines
  1. 1Top 3:
  2. 2Night Harbor 4.6
  3. 3Glass Echo of Glass 4.1
  4. 4Wild Archive 3.9
  5. 5Catalogue:
  6. 6Wild Archive
  7. 7Night Harbor
  8. 8Up
  9. 9Glass Echo of Glass

Loading your progress…

The catalogue lost its order — Python practice · Runtime