def reduce_result(iter, **kwargs):

    import csv
    import sys

    def default_flush_callback(stream):
        stream.flush()
        return stream

    output_stream = kwargs.get('output_stream', sys.stdout)
    flush_schedule = kwargs.get('flush_schedule', 5000)
    flush_callback = kwargs.get('flush_callback', default_flush_callback)

    writer = csv.writer(output_stream)
    count = 0
    for keys, values in iter:
        data = keys + values
        row = [unicode(x).encode('utf-8') for x in data]
        writer.writerow(row)
        count += 1
        if count > flush_schedule:
            output_stream = flush_callback(output_stream)
            count = 0
    flush_callback(output_stream)
dataset/ETHPy150Open chango/inferno/inferno/lib/result.py/reduce_result/original