#
# Torbert, 8.20.2008
#
# Frequency Count, Version 1.2
#
#   Input: dictionary of six-letter words
# Process: determine the frequency of each letter across the entire dictionary
#  Output: each letter A-Z and their total number of appearances in all words
#

from string import lowercase,join

def read_words(fname):
	infile=open(fname)
	temp=infile.read()
	infile.close()
	return temp.split('\n')[:-1]

def main():
	wlist=read_words('words.txt')

	ht=dict(zip(lowercase,[0]*26))
	for w in wlist:
		for ch in w:
			ht[ch]+=1

	pairs=zip(ht.values(),ht.keys())
	pairs.sort()
	pairs.reverse()
	
	print join(['%s %4d'%(y,x) for (x,y) in pairs],'\n') # maybe a little much

if __name__=='__main__':
	main()

#
# Notes
# -----
# Our list comprehension's elements are strings of the form '%s %4d' where
# the (x,y)'s fed into the format string come from the elements of pairs.
#
