Python: MapReduce Word Count

  • Posted on: 19 April 2016
  • By: robin
Python: MapReduce Word Count
text = '''...'''
 
list = text.replace('\n',' ').split(' ')
clist = map(lambda word: (word.lower(), 1), list)
result = {}
for word in clist:
    if(word[0] in result):
        result[word[0]] += 1
    else:
        result[word[0]] = 1
clist = [(k,v) for k,v in result.iteritems()]
clist.sort(key=lambda x: -x[1]) # sorts list by counts (DESC)
clist = filter(lambda x: x[1]>1, clist)
print clist

 

topic: 
python, mapreduce
Field: