#!/usr/bin/python # prints frequency of words found in standard input sorted alphabetically import sys # freq is a dictionary to store frequency of words in text freq = {} # read lines in text, split into words, update freq for line in sys.stdin: for word in line.split(): freq[word] = freq.get(word,0) +1 # words is a list of the words in freq, sorted alpabetically words = freq.keys() words.sort() # print words and their frequencies for w in words: print w, freq[w]