Finding the duration of flights

def time_diff_mins(time1, time2): hours1, mins1 = map(int, time1.split(':')) hours2, mins2 = map(int, time2.split(':')) return (hours2 - hours1) * 60 + (mins2 - mins1) departures_arrivals = [ ('Paris', 'Vienna', '11:25', '12:15'), ('Athens', 'Rome', '10:25', '11:40'), ('Mallorca', 'Aarhus', '09:35', '11:00'), ('Stockholm', 'Oslo', '15:15', '15:45'), ('Warsaw', 'Berlin', '17:25', '18:05'), ('Cologne', 'Lisbon', '18:15', '19:55') ] # First variant durations = {'-'.join([source, destination]): time_diff_mins(source_time, destination_time) for source, destination, source_time, destination_time in departures_arrivals} for route, dur in sorted(durations.items(), key = lambda x: x[1])[::-1]: print(': '.join([route, str(dur) + 'min'])) # Second variant print('\n'.join(': '.join([route, str(dur) + 'min']) for route, dur in sorted(dict(map(lambda x: ('-'.join([x[0], x[1]]), time_diff_mins(x[2], x[3])), departures_arrivals)).items(), key = lambda x: x[1])[::-1])) """ Both produce the same result: Cologne-Lisbon: 100min Mallorca-Aarhus: 85min Athens-Rome: 75min Paris-Vienna: 50min Warsaw-Berlin: 40min Stockholm-Oslo: 30min """