Skip to content

Instantly share code, notes, and snippets.

@rod-dot-codes
Created October 13, 2015 05:47
Show Gist options
  • Save rod-dot-codes/14c7a59cfa5e47cc767f to your computer and use it in GitHub Desktop.
Save rod-dot-codes/14c7a59cfa5e47cc767f to your computer and use it in GitHub Desktop.
Simple Map Reduce Example
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