Created
February 29, 2012 18:34
-
-
Save ecounysis/1943371 to your computer and use it in GitHub Desktop.
MapReduce Python Class
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
# 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