from .parse_links_for_text import parse_links_for_text


def split_and_flip_instructors(course):
    # Take a string like 'Bridges IV, William H.' and split/flip it
    # to 'William H. Bridges IV'. Oh, and do that for each professor.

    if 'instructors' in course:
        instructors = parse_links_for_text(course['instructors'])
        flipped_profs = []

        for prof in instructors:
            string_to_split = prof.split(',')
            actual_name = ''

            for name_part in reversed(string_to_split):
                name_part = name_part.strip()
                actual_name += name_part + ' '

            flipped_profs.append(actual_name.strip())

        return flipped_profs

    return course.get('instructors', [])

from .parse_links_for_text import parse_links_for_text


def split_and_flip_instructors(course):
    # Take a string like 'Bridges IV, William H.' and split/flip it
    # to 'William H. Bridges IV'. Oh, and do that for each professor.

    flipped_profs = []
    instructors = parse_links_for_text(course.get('instructors', []))

    for prof in instructors:
        string_to_split = reversed(prof.split(','))
        actual_name = ' '.join([name_part.strip() for name_part in string_to_split])
        flipped_profs.append(actual_name.strip())

    return flipped_profs

simplify split_and_flip_instructors