def sort_records(data, sort):
  """ Sorts records via 3 methods: gender, birth date, and last name

  Args:
    data:
      Array of dict records to sort.
    sort:
      Sort method to use, one of ['gender', 'birthdate', 'lastname'].

  Returns:
    An array of sorted dict records.
  """
  sorted_data = None
  # sorted by gender (females before males) then by last name ascending.
  # see how it maintains ordering:
  # https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts
  if sort == 'gender':
    # sort by last name first
    sorted_data = sorted(data, key=lambda x: x['lastName'], reverse=True)
    # sort again by gender within that set
    sorted_data = sorted(sorted_data, key=lambda x: x['gender'])
  if sort == 'birthdate':
    # sorted by birth date, ascending
    sorted_data = sorted(data, key=lambda x: x['dateOfBirth'], reverse=True)
  if sort == 'lastname':
    # sorted by last name, descending
    sorted_data = sorted(data, key=lambda x: x['lastName'])
  return sorted_data