def pfunc(inputfields, operation):
    """Parameterized computation of a new field
    
    For example, append a field that is the sum of fields 1 and 3:
    >>> z = pfunc((1, 3), operator.add)
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]
    >>> map(z, database)
    [(10, 25, 30, 40, 50, 60, 65), (100, 250, 300, 10, 500, 600, 260)]
    """
    def z(record):
        newfield = operation(*[record[f] for f in inputfields])
        return record + (newfield,)
    return z
Parameterized computation of a new field
    
    For example, append a field that is the sum of fields 1 and 3:
    >>> z = pfunc((1, 3), operator.add)
    >>> database = [(10, 25, 30, 40, 50, 60), (100, 250, 300, 10, 500, 600)]
    >>> map(z, database)
    [(10, 25, 30, 40, 50, 60, 65), (100, 250, 300, 10, 500, 600, 260)]
    
recipes/Python/473803_Parameterized_database_functions/recipe-473803.py