#
# Torbert, 8.20.2008
#
# Frequency Count, Version 1.1
#
#   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

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=[(ht[ch],ch) for ch in lowercase] # list comprehension
	pairs.sort() # if frequencies are tied then sorts by letter
	pairs.reverse()
	
	for (x,y) in pairs:
		print '%s %4d'%(y,x)

if __name__=='__main__':
	main()

#
# Notes
# -----
# The result of our list comprehension is a list, elements of that list are
# of the form (ht[ch],ch) where the ch's come from the elements of lowercase.
#
