Finish the last commit
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
import sys, re, operator, string
|
||||
from functools import reduce
|
||||
|
||||
try:
|
||||
xrange # Python 2
|
||||
except NameError:
|
||||
xrange = range # Python 3
|
||||
|
||||
|
||||
#
|
||||
# Functions for map reduce
|
||||
#
|
||||
@@ -17,7 +10,7 @@ def partition(data_str, nlines):
|
||||
into chunks of nlines.
|
||||
"""
|
||||
lines = data_str.split('\n')
|
||||
for i in xrange(0, len(lines), nlines):
|
||||
for i in range(0, len(lines), nlines):
|
||||
yield '\n'.join(lines[i:i+nlines])
|
||||
|
||||
def split_words(data_str):
|
||||
@@ -77,4 +70,4 @@ splits = map(split_words, partition(read_file(sys.argv[1]), 200))
|
||||
word_freqs = sort(reduce(count_words, splits))
|
||||
|
||||
for (w, c) in word_freqs[0:25]:
|
||||
print(w, ' - ', c)
|
||||
print(w, '-', c)
|
||||
|
||||
Reference in New Issue
Block a user