def sortkeyfunc(name):
    """Return name in last-first-middle order"""
    name_parts = name.split()
    new_name = ' '.join((name_parts[-1], name_parts[0]))
    if len(name_parts) == 3:
        new_name = ' '.join((new_name, name_parts[1]))
    return new_name
Return name in last-first-middle order
recipes/Python/303177_Sort_names_separate_last_name/recipe-303177.py