<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expand_folder(notebook_or_folder, recursive=False):
 """ If notebook_or_folder is a folder, returns a list containing all notebooks in the folder. Otherwise, returns a list containing the notebook name. If recursive is True, recurses into subdirectories. """

    is_file = os.path.isfile(notebook_or_folder)
    is_dir = os.path.isdir(notebook_or_folder)
    if not (is_file or is_dir):
        raise ValueError(
            '{} is neither an existing file nor a folder.'
            .format(notebook_or_folder)
        )

    if is_file:
        return [notebook_or_folder]

    # Now we know the input is a directory
    if not recursive:
        return glob('{}/*.ipynb'.format(notebook_or_folder))

    # Recursive case
    return [
        os.path.join(folder, filename)
        for folder, _, filenames in os.walk(notebook_or_folder)
        # Skip folders that start with .
        if not os.path.basename(folder).startswith('.')
        for filename in fnmatch.filter(filenames, '*.ipynb')
    ]