INNER CODE UNIT · Python

map_field

lebinh/ngxtop · ngxtop/ngxtop.py:246

def map_field(field, func, dict_sequence):
    """
    Apply given function to value of given key in every dictionary in sequence and
    set the result as new value for that key.
    """
    for item in dict_sequence:
        try:
            item[field] = func(item.get(field, None))
            yield item
        except ValueError:
            pass


def add_field(field, func, dict_sequence):
    """
    Apply given function to the record and store result in given field of current record.
    Do nothing if record already contains given field.
    """

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…