def Filter(func):
    '''
    This is the filter creator function, you can also use it as a decorator.

    usage: Filter(function, *args **keywordArgs)
    args and keywordArgs are automatically passed to the function during 
    iteration.

    The function passed to it must take a valid file path as a first argument
    example:
        @Filter
        def MinSize(file, minsize):
            return os.path.getsize(file) >= minsize:
        # Now you have created a filter that can take a list of files and a
        # minsize argument and apply the minsize condition to the files list
        # Print files in '.' that are 1MB or larger
        for file in MinSize(os.listdir('.'), 1024*1024):
            print file
    '''
    def wrapper(files, *a, **kw):
        for file in files:
            if func(file, *a, **kw):
                yield file
    return wrapper

    This is the filter creator function, you can also use it as a decorator.

    usage: Filter(function, *args **keywordArgs)
    args and keywordArgs are automatically passed to the function during 
    iteration.

    The function passed to it must take a valid file path as a first argument
    example:
        @Filter
        def MinSize(file, minsize):
            return os.path.getsize(file) >= minsize:
        # Now you have created a filter that can take a list of files and a
        # minsize argument and apply the minsize condition to the files list
        # Print files in '.' that are 1MB or larger
        for file in MinSize(os.listdir('.'), 1024*1024):
            print file
    
recipes/Python/578084_Create_apply_filters_lists_file/recipe-578084.py