Question: Problem 0 a . Alphabet Dictionary Given the following string, write a program that counts how many times each letter or number has been used

Problem 0a. Alphabet Dictionary
Given the following string, write a program that counts how many times each letter or number has
been used in the string. Use a dictionary to store your results.
Enter a phrase: "The lazy dog jumped over the curious cat"
Here's a sample running of your program:
Report in ascending order by ASCII value:
Enter a phrase: "The lazy dog jumped over the curious cat"
7
T 1
a 2
c 2
d 2
e 4
g 1
h 2
i 1
j 1
l 1
m 1
o 3
p 1
r 2
s 1
t 2
u 3
v 1
y 1
z 1Note this example only includes letters. Numbers would be placed, from 0-9, before the letters and
after the spaces.
Problem 0b
In the example above, the ts are counted as separate letters. We want to count lowercase and
uppercase letters as the same and remove all characters that are not alphanumeric.
Begin by writing this convenience function - this function will be useful to make sure that all of the
string data you will be working with is formatted correctly.
# function: cleanup_string
# input: a string to clean up
# processing: (1) makes the entire string lowercase.
# (2) retains only alphabetic and numeric characters
# all punctuation, spaces, and special characters removed]
# output: returns the cleaned up string
def cleanup_string(data):
# TEST CODE
test1= cleanup_string("Hello World! This is a simple test of this function!"
)
print (test1)
# helloworldthisisasimpletestofthisfunction
test2= cleanup_string("ABC123abc this is Another TEST!!!#@@")
print (test2)
# abc123abcthisisanothertest
In part a, the string would be converted to
thelazydogjumpedoverthecuriouscat
and the output would be
Report in ascending order by ASCII value:
a 2c 2
d 2
e 4
g 1
h 2
i 1
j 1
l 1
m 1
o 3
p 1
r 2
s 1
t 3
u 3
v 1
y 1
z 1
Problem 0 Points (15):
Dictionary is used to track how many of each letter; letters are keys, counts are values (3
points)
Output of number and letter counts is sorted in ascending order (2 points)
Two test cases that ensure that any non-alphanumeric characters are removed and
letters and numbers are correctly counted (5 points each; 2 points each for the cleaned
string, 3 points each for the sorted counts)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!