#!/usr/bin/python # TYPE:default # DESC:A word counter. Gets words (one word per line) and tells how many of each were seen. import sys from chemParse import add_s print """ ::Word Counter:: Enter a list of words, one word per line, and press ^D (Control-D) when finished. Your words will be counted. """ words = sys.stdin.readlines() def countWords(words): amounts = {} for word in words: word = word.strip() if word != '': amounts[word] = amounts.get(word, 0) + 1 return amounts wordList = countWords(words) for word, amount in wordList.items(): print "We saw '%s' %d %s!" % (word, amount, add_s('time', amount))