#!/usr/bin/python3 # # This program reads a text file from the standard input and prints # the list of all the words in the text file, each followed by the # number of times the word occurs in the text. Words in the input are # the maximal-length sequences of alphabetic characters (e.g., a-z). # So, a word does not include spaces or punctuation characters. # import sys import string def line_to_words(line): words = [] w = '' for c in line: if c.isalpha(): w += c else: if not w == '': words.append(w) w = '' if not w == '': words.append(w) return words freqs = {} for line in sys.stdin: for word in line_to_words(line): if word in freqs: freqs[word] = freqs[word] + 1 else: freqs[word] = 1 for c, f in freqs.items(): print(c, f)