#
# Torbert, 8.20.2008
#
# Frequency Count, Version 1.0
#
#   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)) # hash table
	for w in wlist:
		for ch in w:
			ht[ch]+=1
	
	for ch in lowercase: # in Windows use lowercase[:26] instead
		print '%s %4d'%(ch,ht[ch])

if __name__=='__main__':
	main()

#
# Notes
# -----
# 1. Loop over words in dictionary (5K), loop over letters in word (6),
#    increment count for that letter (30K total)
# 2. Loop over letters (26), loop over all words (5K), loop over letters
#    in word (6), count occurrences of current letter (780K total)
#

