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

Homework 1 (Due: 25 September 2023)

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 found in the file.

.

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

lipogram.txt

ra.txt

Here is a program template:


import sys
import matplotlib.pyplot as plt

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
	pass

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

def main():
  counts = get_counts(sys.argv[1])
  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