Honors 1000, Productive Data Manipulation in Python and SQL (Fall 2019)

Homework 3 (Due: 30 October 2019)

Write a Python program, called histogram.py, that reads a text file and plots a histogram of letter counts for each letter of the alphabet.

.

Here are couple of text files for you to test your program against:

lipogram.txt

ra.txt

Here is a program template:


import matplotlib.pyplot as plt
%matplotlib inline 

def get_counts(fname):
# this function takes the name of a file as input parameter, fname
# it then reads the file into a string variable
# then proceeds to process the string for the count of letters
# answer should be returned in a list of 26 numbers

def draw(counts):
# this function takes as input the "counts" list
# the function then proceeds to plot the histogram

def main():
  counts = get_counts("lipogram.txt")
  draw(counts)
 
main()

NOTES:

  1. the Python commands to read from file into a string object is:
      with open(fname) as f:
        data = f.read().lower()
    
  2. Use the String object's count() method to get the count of character c in a string
  3. Sample code to plot histogram