def map_reduce(inputs, mapper, reducer):
 collector = defaultdict(list)
 for input in inputs:
  for (key, value) in mapper(input):
   collector[key].append(value)
 return [output for (key, values) in collector.items() for output in reducer(key, values)]

def map_reduce ( inputs , mapper , reducer ) : collector = defaultdict ( list ) for input in inputs : for ( key , value ) in mapper ( input ) : collector [ key ] . append ( value ) return [ output for ( key , values ) in collector . items ( ) for output in reducer ( key , values ) ]
runs mapreduce on the inputs using mapper and reducer .