def rfunc(inputfield, operation):
    """Parameterized reduce operation
    
    For example, find the maximum value of field 2:
    >>> r = rfunc(2, max)
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]
    >>> reduce(r, database, 0)
    300
    """
    def z(cumval, record):
        x = record[inputfield]
        return operation(cumval, x)
    return z
Parameterized reduce operation
    
    For example, find the maximum value of field 2:
    >>> r = rfunc(2, max)
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]
    >>> reduce(r, database, 0)
    300
    
recipes/Python/473803_Parameterized_database_functions/recipe-473803.py