def _time_sort_key(d):
 container_id = (d.get('container_id') or '')
 attempt_parts = (d.get('attempt_id') or d.get('task_id') or d.get('job_id') or d.get('application_id') or _to_job_id(container_id) or '').split('_')
 container_parts = container_id.split('_')
 timestamp_and_step = '_'.join(attempt_parts[1:3])
 task_type = '_'.join(attempt_parts[3:4])
 task_num = ('_'.join(attempt_parts[4:5]) or '_'.join(container_parts[(-1):]))
 attempt_num = ('_'.join(attempt_parts[5:6]) or '_'.join(container_parts[(-2):(-1)]))
 return (timestamp_and_step, container_id, task_type, attempt_num, task_num)

def _time_sort_key ( d ) : container_id = ( d . get ( 'container_id' ) or '' ) attempt_parts = ( d . get ( 'attempt_id' ) or d . get ( 'task_id' ) or d . get ( 'job_id' ) or d . get ( 'application_id' ) or _to_job_id ( container_id ) or '' ) . split ( '_' ) container_parts = container_id . split ( '_' ) timestamp_and_step = '_' . join ( attempt_parts [ 1 : 3 ] ) task_type = '_' . join ( attempt_parts [ 3 : 4 ] ) task_num = ( '_' . join ( attempt_parts [ 4 : 5 ] ) or '_' . join ( container_parts [ ( - 1 ) : ] ) ) attempt_num = ( '_' . join ( attempt_parts [ 5 : 6 ] ) or '_' . join ( container_parts [ ( - 2 ) : ( - 1 ) ] ) ) return ( timestamp_and_step , container_id , task_type , attempt_num , task_num )
sort key to sort the dictionaries containing ids roughly by time .