Kodewick
Start learning →
Basic←→0 / 80

Airport arrivals

#072BasicStringsSorting5 min

The arrivals board has one flight per line: a flight code and a landing time, like "CA9 9:30". Write arrival_order(text) to sort them earliest first and return the codes. Turn each time into minutes after midnight before comparing (or "9:30" lands after "14:05"). No two times are the same.

Examples
arrival_order("MU5 14:05\nCA9 9:30\nZH2 9:05")→['ZH2', 'CA9', 'MU5']
arrival_order("")→[]
main.py
def arrival_order(text):
    flights = []
    for line in text.splitlines():
        code, time = line.split()
        h, m = time.split(":")
        # your code here: put (minutes, code) into flights
    # your code here: sort flights
    return [code for minutes, code in flights]
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.