def xfunc(fields):
    """Parameterized extract operation

    For example, extract fields 1, 3, and 4
    >>> x = xfunc((1,3,4))
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]     
    >>> map(x, database)
    [(25, 40, 50), (250, 10, 500)]
    """
    def z(record):
        return tuple([record[f] for f in fields])
    return z
Parameterized extract operation

    For example, extract fields 1, 3, and 4
    >>> x = xfunc((1,3,4))
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]     
    >>> map(x, database)
    [(25, 40, 50), (250, 10, 500)]
    
recipes/Python/473803_Parameterized_database_functions/recipe-473803.py