14792 - Daily schedule sort   

Description

You’re an NTHU computer science student, and your schedule is packed with homework, labs, tests, and quizzes. Today you’ve got a lot to do. Worried you might miss something, you decide to put all your activities into a program and sort them by which one happens first. The problem are for every event you have, the time that you use to track the event have 2 different format, 12 hour format (09:00 AM or 12:00 PM) and 24 hour format (00:00 - 23:59). you might need to define a specific funtion to handle these so the sorting method is correct.

You can use this code snippet and complete the functions:

def sort_time_activity(items):
    pass

tokens = input().split(', ')
items = [', '.join(tokens[i:i+2]).strip('"') for i in range(0, len(tokens), 2)]

result = sort_time_activity(items)
print("\n".join(result))

Hint

use map() to map the value of each item, and use sort() and lambda expression to sort it by the value you gave to each item 

Input

got a list of activity for today with one item looks like:

"09:00 PM, study programming", "23:00, meet friends in the bar", "12:00 AM, calculus homework"

with the format "time, activity_name" for every event.

Output

sorted activity by its time from what come first to last:

12:00 AM, calculus homework
09:00 PM, study programming
23:00, meet friends in the bar

 

if there is 2 same time stamp, sort it base which appear first:

Input:

"12:00 PM, Noon", "12:00 AM, Midnight", "00:00, Start of Day", "12:00 PM, Town Hall"

Output:

12:00 AM, Midnight
00:00, Start of Day
12:00 PM, Noon
12:00 PM, Town Hall

Sample Input  Download

Sample Output  Download

Tags




Discuss