We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Someone copy-pasted a wordcount solution without thinking through the differences between the necessary structure for a wordcount and for an intersection. Line numbers are significant in wordcount, but not this problem.
The Python version also asks much harder questions of the solver than the other languages, which only ask you to complete an equality check.
The output format is also wrong, and you must either edit the class or bypass it to get the correct answer.
Here is a template to use. It is still not as easy as the versions in the other three languages.
# This template is based on the framework supplied for a similar challenge, in a Coursera Data Science course: https://www.coursera.org/course/datasci# And the code supplied here: https://github.com/uwescience/datasci_course_materials/blob/master/assignment3/wordcount.pyimportjsonimportsysfromcollectionsimportOrderedDictclassMapReduce:def__init__(self):self.intermediate=OrderedDict()self.result=[]defemitIntermediate(self,key,value):self.intermediate.setdefault(key,[])self.intermediate[key].append(value)defemit(self,value):self.result.append(value)defexecute(self,data,mapper,reducer):forlineindata:record=json.loads(line)mapper(record)forkeyinself.intermediate:reducer(key,self.intermediate[key])returnself.resultmapReducer=MapReduce()defmapper(record):key=record["key"]value=record["value"]# ADD THE REQUIRED LOGIC BELOW# You may need to add some lines for the mapper logic to work# At the end, you need to complete the emit intermediate stepmapReducer.emitIntermediate(?,?)defreducer(key,list_of_values):# ADD THE REQUIRED LOGIC BELOW# You may need to add some lines for the reducer logic to work# At the end, you need to complete the emit stepmapReducer.emit(?)if__name__=='__main__':inputData=[]nr,ns=map(int,raw_input().split())foriinrange(nr):k=int(raw_input())inputData.append(json.dumps({"key":k,"value":"R"}))foriinrange(ns):k=int(raw_input())inputData.append(json.dumps({"key":k,"value":"S"}))result=mapReducer.execute(inputData,mapper,reducer)forninresult:printn
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Relational MapReduce Patterns #1 - Intersections
You are viewing a single comment's thread. Return to all comments →
Someone copy-pasted a wordcount solution without thinking through the differences between the necessary structure for a wordcount and for an intersection. Line numbers are significant in wordcount, but not this problem.
The Python version also asks much harder questions of the solver than the other languages, which only ask you to complete an equality check.
The output format is also wrong, and you must either edit the class or bypass it to get the correct answer.
Here is a template to use. It is still not as easy as the versions in the other three languages.