def _organize_output(output, combine_map, file_key, combine_arg_keys):
    """Combine output details for parallelization.

    file_key is the key name of the output file used in merging. We extract
    this file from the output data.

    combine_arg_keys are extra items to pass along to the combine function.
    """
    out_map = collections.defaultdict(list)
    extra_args = collections.defaultdict(list)
    final_args = collections.OrderedDict()
    extras = []
    for data in output:
        cur_file = data.get(file_key)
        if not cur_file:
            extras.append([data])
        else:
            cur_out = combine_map[cur_file]
            out_map[cur_out].append(cur_file)
            extra_args[cur_out].append([data[x] for x in combine_arg_keys])
            data[file_key] = cur_out
            if cur_out not in final_args:
                final_args[cur_out] = [data]
            else:
                extras.append([data])
    combine_args = [[v, k] + _get_extra_args(extra_args[k], combine_arg_keys)
                    for (k, v) in out_map.items()]
    return combine_args, list(final_args.values()) + extras
def _organize_output ( output , combine_map , file_key , combine_arg_keys ) : out_map = collections . defaultdict ( list ) extra_args = collections . defaultdict ( list ) final_args = collections . OrderedDict ( ) extras = [ ] for data in output : cur_file = data . get ( file_key ) if not cur_file : extras . append ( [ data ] ) else : cur_out = combine_map [ cur_file ] out_map [ cur_out ] . append ( cur_file ) extra_args [ cur_out ] . append ( [ data [ x ] for x in combine_arg_keys ] ) data [ file_key ] = cur_out if cur_out not in final_args : final_args [ cur_out ] = [ data ] else : extras . append ( [ data ] ) combine_args = [ [ v , k ] + _get_extra_args ( extra_args [ k ] , combine_arg_keys ) for ( k , v ) in out_map . items ( ) ] return combine_args , list ( final_args . values ( ) ) + extras
Combine output details for parallelization.

    file_key is the key name of the output file used in merging. We extract
    this file from the output data.

    combine_arg_keys are extra items to pass along to the combine function.