Question: Question # 5 : frequency ( txt ) 5 pts Returns a dictionary with the frequency count of each alphabet letter ( in lowercase )

Question #5: frequency(txt)5 pts
Returns a dictionary with the frequency count of each alphabet letter (in lowercase) in txt. You
cannot make assumptions about the contents in txt.
Preconditions and Postconditions
txt: non-empty str
Returns: dict -> frequency count
Useful methods:
The str.isalpha() method returns True if all characters in the string are alphabetic and there
is at least one character, False otherwise.
o 's'.isalpha() returns True
o '9'.isalpha() returns False
The str.lower() method returns a copy of the string with all the cased characters converted
to lowercase.
o 'A'.lower() returns 'a'
ord() returns an integer representing the Unicode code point of that character.
o ord('a') returns 97
You are NOT allowed to use the count() method or any other Python count libraries such as
Counter, mode, the min() and max() methods. You will not get credit if you used them in your
code, even if your code passed the test cases.
Example:
>>> frequency('mama')
{'m': 2,'a': 2}
>>> answer = frequency('We ARE Penn State!!!')
>>> answer
{'w': 1,'e': 4,'a': 2,'r': 1,'p': 1,'n': 2,'s': 1,'t': 2}

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 Databases Questions!