File: wordcount.py

package info (click to toggle)
toolz 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 5,573; makefile: 136; sh: 2
file content (12 lines) | stat: -rw-r--r-- 358 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
from toolz import *


def stem(word):
    """ Stem word to primitive form """
    return word.lower().rstrip(",.!:;'-\"").lstrip("'\"")

wordcount = comp(frequencies, partial(map, stem), str.split)

if __name__ == '__main__':
    print(wordcount("This cat jumped over this other cat!"))
    # prints {'this': 2, 'cat': 2, 'jumped': 1, 'over': 1, 'other': 1}