MapReduce job to yield top 10 values using Python's MRjob
<p>I want this map reduce job (code below) to output the top 10 most rated products. It keeps giving me the following error message: </p>

<p>it = izip(iterable, count(0,-1))                    # decorate
TypeError: izip argument #1 must support iteration.</p>

<p>I'm thinking it has to do with the <em>nlargest</em> function I am trying to apply. </p>

<p>Any pointers?</p>

<p>Thank you!</p>

<pre><code>from mrjob.job import MRJob
from mrjob.step import MRStep
from heapq import nlargest


class MostRatedProduct(MRJob):

def steps(self):
    return [
        MRStep(mapper = self.mapper_get_ratings,
               reducer = self.reducer_count_ratings),
        MRStep(reducer = self.reducer_find_top10)
    ]


def mapper_get_ratings(self, _, line):
    (userID, itemID, rating, timestamp) = line.split(',')
    yield itemID, 1

def reducer_count_ratings(self, itemID, ratingCount):
    yield None, (sum(ratingCount), itemID)

def top_10(self, ratingPair):
    for ratingTotal, itemID in ratingPair:
        top_rated = nlargest(10, ratingTotal)
    for top_rated in ratingTotal:
        return (ratingTotal, itemID)

def reducer_find_top10(self, key, ratingPair):
    ratingTotal, itemID = self.top_10(ratingPair)
    yield ratingTotal, itemID


if __name__ == '__main__':
    MostRatedProduct.run()
</code></pre>