Question: Problem 7 : Frequency Distribution In this problem, we will create a function named freq _ dist ( ) that creates a frequency distribution based

Problem 7: Frequency Distribution
In this problem, we will create a function named freq_dist() that creates a frequency distribution based on the
elements of a list. The function will accept a list of values as its input and will return two lists. One returned list will contain
the unique values found in the argument list, while the second list will contains counts of the number of times each of the
unique values occurred. For example: If mylist =[10,10,20,10,20,30,20,20,30,40], then
freq_dist(mylist) should return the following tuple: ([10,20,30,40],[3,4,2,1]).
5
Define a function named freq_dist() with a single parameter x, which is expected to be a list. This function should
return two lists. You can name these lists whatever you like, but for the sake of discussion, let's call them values and
counts.
The list values should be a sorted list of unique values appearing in x. You can (and should) use the function
you wrote in Problem 6 to create this list.
The list counts should be a list of integers. Each integer should be a count of the number of times a particular
value in values appears in x.
An outline of this function is provided below:
1. Find the list of unique values, referred to above as values.
2. Create an empty list for counts.
3. Loop over values. Each time the loop executes, you should count the number of times the current element of
values appears in the list x, appending the result to the counts list. I recommend using the counts() list
method for this (although you could also perform this using a second loop).
4. Return the two lists values and counts.
We will now test the freq_dist() function. Create a new code cell to perform the steps below.
Create the list shown below:
grades =['A','D','A','C','B','F','A','D','C',
'B','F','A','C','B','A','B','B','C',
'B','F','D','D','A','C','B','B','D']
Call the freq_dist() function on this list. Display the resulting lists with messages formatted as shown below. Match
the formatting exactly. The lists displayed should be left-aligned.
Unique Values: xxxx
Frequencies: xxxx

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!