def field_map(dictseq, key_map):
    """Field mapping function from David Beazley's excellent series on generators
    @dictseq: iterable producing dictionaries
    @key_map: mapping { key -> func } where @key must be a valid key in @dictseq elements
    Produce sequence of dictionaries, with values for keys replaced by function results
    """
    for d in dictseq:
        for key, func in key_map.items():
            d[key] = func(d[key])
        yield d
