def apply_sorting(records, sorting):
 result = list(records)
 if (not result):
  return result
 first_record = result[0]
 def column(first, record, name):
  empty = first.get(name, float('inf'))
  subfields = name.split('.')
  value = record
  for subfield in subfields:
   value = value.get(subfield, empty)
   if (not isinstance(value, dict)):
    break
  return value
 for sort in reversed(sorting):
  result = sorted(result, key=(lambda r: column(first_record, r, sort.field)), reverse=(sort.direction < 0))
 return result

def apply_sorting ( records , sorting ) : result = list ( records ) if ( not result ) : return result first_record = result [ 0 ] def column ( first , record , name ) : empty = first . get ( name , float ( 'inf' ) ) subfields = name . split ( '.' ) value = record for subfield in subfields : value = value . get ( subfield , empty ) if ( not isinstance ( value , dict ) ) : break return value for sort in reversed ( sorting ) : result = sorted ( result , key = ( lambda r : column ( first_record , r , sort . field ) ) , reverse = ( sort . direction < 0 ) ) return result
sort the specified records .