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.
defexecute(self,data,mapper,reducer):forlineindata:record=json.loads(line)mapper(record)forkeyinself.intermediate:reducer(key,self.intermediate[key])jenc=json.JSONEncoder()foriteminself.result:printitem[1]# Obviously, to match the output the originator expects, you have to repair the faulty print statement AND only output one number. It's up to you whether the "key" or the value if what you want output in this case. For this trivial version of map/reduce, we don't need a special value in the reducer.)# print "{\"key\":\""+item[0]+"\",\"value\":" + str(item[1]) + "}"
EDIT: Originally, I forgot, first line is number of entries. You have to ignore the first data item.
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 #2 - Selections
You are viewing a single comment's thread. Return to all comments →
Yes, the fix is extremely easy
Code fixes :
EDIT: Originally, I forgot, first line is number of entries. You have to ignore the first data item.