Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created February 29, 2012 18:34
Show Gist options
  • Save ecounysis/1943371 to your computer and use it in GitHub Desktop.
Save ecounysis/1943371 to your computer and use it in GitHub Desktop.
MapReduce Python Class
# I don't know whether this is valuable or meaningful, but it seems interesting.
class MR:
def process(self,the_list,the_map_function,the_reduce_function,the_initial_value):
return reduce(the_reduce_function, map(the_map_function, the_list), the_initial_value)
def sum1(x):
return MR().process(x, (lambda x: x), (lambda x,y: x+y), 0)
def len1(x):
return MR().process(x, (lambda x: 1), (lambda x,y: x+y), 0)
def avg(x):
return sum1(x)/len1(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment