Created
October 13, 2015 05:47
-
-
Save rod-dot-codes/14c7a59cfa5e47cc767f to your computer and use it in GitHub Desktop.
Simple Map Reduce Example
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
from collections import Counter | |
import re | |
from functools import reduce | |
def reduce_line(line): | |
words = re.findall('\w+',line.lower()) | |
return Counter(words) | |
maps = map(reduce_line, open('time_machine.txt').readlines()) | |
z = reduce(lambda x,y: x+y, maps) | |
print(z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment