def parse_roster(roster, email=False):
    """Extract desired information from a string representation of a roster
    file.

    Args:
        roster: string representation of a roster file
        email: whether email should be parsed as well as username

    Returns:
        A list of student usernames, or a list of dictionaries containing
        student emails and usernames if email param is specified.
    """
    if not email:
        students = []
        for line in roster:
            if not line.strip():
                continue
            line = line.strip()
            line = line.split('|')
            students.append(line[0])
        return students
    else:
        students = []
        for line in roster:
            if not line.strip():
                continue
            student = {}
            line = line.strip()
            line = line.split('|')
            print(line)
            student['username'] = line[0]
            student['email'] = line[16]
            students.append(student)
        return students
