<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def order_search_results(query, search_results):
 """ order of results should be a) query in first name, b) query in last name """


    results = search_results

    results_names = []
    old_query = query
    query = query.split(' ')

    first_word = ''
    second_word = ''
    third_word = ''

    if(len(query) < 2):
        first_word = old_query
    else:
        first_word = query[0]
        second_word = query[1]

        if(len(query) > 2):
            third_word = query[2]

    # save results for multiple passes
    results_second = []
    results_third = []

    for result in results:

        result_list = result.split(' ')

        try:
            if(result_list[0].startswith(first_word)):
                results_names.append(result)
            else:
                results_second.append(result)
        except:
            results_second.append(result)

    for result in results_second:

        result_list = result.split(' ')

        try:
            if(result_list[1].startswith(first_word)):
                results_names.append(result)
            else:
                results_third.append(result)
        except:
            results_third.append(result)

    # results are either in results_names (filtered)
    # or unprocessed in results_third (last pass)
    return results_names + results_third