human
Complete this python program:
def join_things(fields, deleted=False, spam=True):
assistant
#Here is the Python program you requested.

    """A reducer that joins thing table dumps and data table dumps
    """
    counters = {'processed': 0, 'skipped': 0}
    def process(thing_id, vals):
        data = {}
        thing = None
        for val in vals:
            if (val[0] == 'thing'):
                thing = format_dataspec(val, ['data_type', 'thing_type', 'ups', 'downs', 'deleted', 'spam', 'timestamp'])
            elif (val[0] == 'data'):
                val = format_dataspec(val, ['data_type', 'thing_type', 'key', 'value'])
                if (val.key in fields):
                    data[val.key] = val.value
        if ((thing is not None) and (deleted or (thing.deleted == 'f')) and (spam or (thing.spam == 'f')) and all(((field in data) for field in fields))):
            counters['processed'] += 1
            (yield ((thing_id, thing.thing_type, thing.ups, thing.downs, thing.deleted, thing.spam, thing.timestamp) + tuple((data[field] for field in fields))))
        else:
            counters['skipped'] += 1
    mr_reduce(process)
    print >>sys.stderr, ('%s    items    processed,    %s    skipped' % (counters['processed'], counters['skipped']))