logo CodeStepByStep logo

start_letters

Language/Type: Python collections dict

Write a function named start_letters that accepts a file name as a parameter, reads this text file, and produces a dictionary of counters based on what character each word in the file starts with, case-insensitively. For example, if the file contains the text "to be or not to be", your dictionary would store {"b": 2, "n": 1, "o": 1, "t": 2}. Print the mappings in sorted order in the following format. You may assume that every word token in the file begins with a letter from A-Z in upper or lowercase.

b 2
n 1
o 1
t 2
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.