def gFilter(f, gList):
    """Generalized version of filter() - work on infinite list"""
    if f is None:
        f = lambda x: x
    for x in gList:
        # WARNING: may fall into forever loop
        # without yielding anything if f(x) is
        # always false from a certain x onwards
        if f(x):
            yield x
Generalized version of filter() - work on infinite list
recipes/Python/170995_Manipulating_infinite_lists_implemented/recipe-170995.py