Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

compare and contrast positivity and negativity;

Answered: 1 week ago