<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _walk(recursion):
 """Returns a recursive or non-recursive directory walker"""

    try:
        from scandir import walk as walk_function
    except ImportError:
        from os import walk as walk_function

    if recursion:
        walk = partial(walk_function)
    else:
        def walk(path):  # pylint: disable=C0111
            try:
                yield next(walk_function(path))
            except NameError:
                yield walk_function(path)
    return walk