The Python libraries (versions 2 and 3) for WebMapReduce expect the mapper and reducer to be defined by the following functions:
Map the input pair composed of key and value. Both arguments are strings.
Reduce the intermediate values associated with key. values is an iterator that yields string values, and key is a string.
Output is given through the Wmr.emit() function.
The following mapper and reducer demonstrate WordCount in Python 3:
def mapper(key, value): words = key.split() for word in words: Wmr.emit(word, 1)
def reducer(key, values): count = 0 for value in values: count += int(value) Wmr.emit(key, count)