human
I wrote the below code

    def flatten(xs):
        'Convert    lisp-style    (a,    (b,    (c,    ())))    list    into    a    python    list.\n                                Not    a    general    flatten    function.    '
        p = []
        while (xs != ()):
            p.append(xs[0])
            xs = xs[1]
        return p
    def find_path_to_course():
        'Find    a    path    up    the    location    graph    to    a    node    with    the\n                                specified    category.\n\n                                If    no    path    exists,    return    None.\n\n                                If    a    path    exists,    return    it    as    a    tuple    with    root    location    first,    and\n                                the    target    location    last.\n                                '
        queue = [(usage_key, ())]
        while (len(queue) > 0):
            (next_usage, path) = queue.pop()
            parent = modulestore.get_parent_location(next_usage)
            if (next_usage.block_type == 'course'):
                path = (next_usage, path)
                return flatten(path)
            elif (parent is None):
                return None
            newpath = (next_usage, path)
            queue.append((parent, newpath))
    with modulestore.bulk_operations(usage_key.course_key):
        if (not modulestore.has_item(usage_key)):
            raise ItemNotFoundError(usage_key)
        path = find_path_to_course()
        if (path is None):
            raise NoPathToItem(usage_key)
        if full_path:
            return path
        n = len(path)
        course_id = path[0].course_key
        chapter = (path[1].name if (n > 1) else None)
        section = (path[2].name if (n > 2) else None)
        vertical = (path[3].name if (n > 3) else None)
        position = None
        if (n > 3):
            position_list = []
            for path_index in range(2, (n - 1)):
                category = path[path_index].block_type
                if ((category == 'sequential') or...

What's a good function header?
assistant
#Here is Python program to find    a    path    up    the    location    graph    to    a    node    with    the\n                                specified    category.

def path_to_location(modulestore, usage_key, full_path=False):