Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(MUST FOLLOW ALL REQUESTS)Thanks! Create the file letterCount.c . The program wi

ID: 671849 • Letter: #

Question

(MUST FOLLOW ALL REQUESTS)Thanks!

Create the file letterCount.c.

The program will get the name of a file from the command line and count the number of times each letter of the alphabet occurs within that file. This means that the letters 'A' and 'a' are considered the same.

Assume you are given the file lab4-hard-data1.in with contents

Here is a run of your program with that file:

Here is the file lab4-hard-data2.in with contents

Here is a run of your program with that file:

Hints and Suggestions

Here is a rough outline of what your program should look like

If you look at the ASCII table you will notice that lowercase characters are contiguous to each other. You should be able to convert them from their character representation to their index offset in the array.

You will receive no credit if:

You do not name your files correctly or place them in the wrong directory

Your program does not compile

Your program crashes during testing

You will receive a deduction if:

You don't print the earliest (deduct 10 points)

You don't print the last (deduct 10 points)

Explanation / Answer

import sys
import string

text = sys.argv[1]

text = text.lower()

letter_counts = {}
for letter in text:
            if letter != " ":
                        if letter != ".":
                                    letter_counts[letter] = letter_counts.get(letter, 0) +1

letter_keys = letter_counts.keys()
letter_keys.sort()


for element in letter_keys:
            print element, letter_counts[element]