Kodewick
Start learning →
Mini challenge←→0 / 80

Today's lessons

#078Mini challengeStringsSorting7 min

The timetable has one lesson per line: day hour subject, like "Mon 10 Art". Write day_plan(text, day): pick that day's lessons, sort them from earliest to latest, and return the subjects. If there are no lessons that day, return an empty list.

Examples
day_plan("Mon 10 Art\nTue 9 PE\nMon 8 Maths", "Mon")→['Maths', 'Art']
day_plan("Tue 9 PE", "Fri")→[]
main.py
def day_plan(text, day):
    lessons = []
    for line in text.splitlines():
        # your code here: split the line; if it's this day, put (hour, subject) into lessons
        pass
    # your code here: sort lessons
    return [subject for hour, subject in lessons]
Ctrl + Enter runs too
Result

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