human
I am working on the file "Sessions/Session03/Day3/MapReduce.ipynb".
The first task is:
Problem 1b)
How would you use this to compute the MEAN of the input data.
Problem 1c)
Think about how you would adapt this this to compute the MEDIAN of the input data. Do not implement it today! If it seems hard, it is because it is.
What special properties do SUM, MAX, MEAN have that make it trivial to represent in MapReduce? 
Problem 2)
Let's go through a more complete example. The following MapReduce class faithfully implements the MapReduce programming model, but it executes entirely on one processor -- it does not involve parallel computation.
Setup
First, download the data:
$ curl -O https://lsst-web.ncsa.illinois.edu/~yusra/escience_mr/books.json
$ curl -O https://lsst-web.ncsa.illinois.edu/~yusra/escience_mr/records.json
Can you write Python code for it?
assistant
#Here is Python code to compute the MEAN of the input data.

DATA_DIR = './data' # Set your path to the data files

import json
import sys

class MapReduce:
    def __init__(self):
        self.intermediate = {}
        self.result = []

    def emit_intermediate(self, key, value):
        self.intermediate.setdefault(key, [])
        self.intermediate[key].append(value)

    def emit(self, value):
        self.result.append(value) 

    def execute(self, data, mapper, reducer):
        for line in data:
            record = json.loads(line)
            mapper(record)

        for key in self.intermediate:
            reducer(key, self.intermediate[key])

        jenc = json.JSONEncoder()
        for item in self.result:
            print(jenc.encode(item))