def _merge_and_sort_errors(errors):
 key_to_error = {}
 for error in errors:
  key = _time_sort_key(error)
  key_to_error.setdefault(key, {})
  key_to_error[key].update(error)
 def sort_key(key_and_error):
  (key, error) = key_and_error
  return (key[0], bool(error.get('task_error')), key[1:])
 return [error for (key, error) in sorted(key_to_error.items(), key=sort_key, reverse=True)]

def _merge_and_sort_errors ( errors ) : key_to_error = { } for error in errors : key = _time_sort_key ( error ) key_to_error . setdefault ( key , { } ) key_to_error [ key ] . update ( error ) def sort_key ( key_and_error ) : ( key , error ) = key_and_error return ( key [ 0 ] , bool ( error . get ( 'task_error' ) ) , key [ 1 : ] ) return [ error for ( key , error ) in sorted ( key_to_error . items ( ) , key = sort_key , reverse = True ) ]
merge errors from one or more lists of errors and then return them .