Created
August 23, 2014 09:08
-
-
Save airekans/3845aa0076d335689013 to your computer and use it in GitHub Desktop.
A MapReduce example: Given a list of (user_name, filename) pair, get a list of (filename, owner_count)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = [("user_a", "file_a"), ("user_b", "file_b"), ("user_c", "file_b")] | |
filenames = map(lambda p: p[1], l) | |
def reduce_func(res, filename): | |
if filename not in res: | |
res[filename] = 0 | |
res[filename] += 1 | |
return res | |
file_cnt = reduce(reduce_func, filenames, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment