Skip to content

Instantly share code, notes, and snippets.

@airekans
Created August 23, 2014 09:08
Show Gist options
  • Save airekans/3845aa0076d335689013 to your computer and use it in GitHub Desktop.
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)
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