# python program to study character frequencies
# 
# Ethan Bolker
# March 2015
# Math 480 hw2

import sys

def createfrequencytable( filename ):
    table = {} 
    for line in open(filename):
        for c in line.lower(): # convert to lower case
           if str.isalpha(c):  # count only a,b,c ...
               if c in table.keys():
                   table[c] += 1
               else:
                   table[c] = 1
    return(table)

import operator

# Fake the default implicit main method that tells python
# where to start execution - the right trick for testing inside a module.
# 
if __name__ == '__main__':
   table = createfrequencytable( sys.argv[1] )
   sorted_table = sorted(table.items(), key=operator.itemgetter(1))
   print(sorted_table)
#  now I know sorted_table is a list of tuples
   for pair in reversed(sorted_table):
      print(pair[0] + ": " + str(pair[1]))
