Alright, now I'm going to throw you into the deep end of the pool here, look at this big scary line:
totalsByAge = rdd.mapValues(lambda x: (x, 1)).reduceByKey(lambda x, y: (x[0] + y[0], x[1] + y[1]))
However, if we break it down into its components, what's going on here is pretty straightforward. What we need to do next is to aggregate our RDD information somehow. So let's just break this totalsByAge line down, one component at a time. You can see, we have sort of a compound operation going on here; we're taking our RDD of age and number of friend key/value pairs and we're calling mapValues on it, and then we're taking the resulting RDD and calling reduceByKey on it. Let's take ...