Question: Python, Return a dictionary that strores the frequency of each element. Create a function calcFreqList that does exactly the same with the following requirements: the

Python, Return a dictionary that strores the frequency of each element.

Create a function calcFreqList that does exactly the same with the following requirements:

  • the list is passed as the argument "arg1"
  • the function returns a dictionary that stores the frequency of each element

Python, Return a dictionary that strores the frequency of each element. Create

The following code calculates the frequency of elements in a list.

In [ ]:

 
mylist = ['one','two','three','one','four', 'two', 'one']
setp = set(mylist)
freq = dict().fromkeys(setp, 0)
for p in mylist:
 freq[p] += 1
print(freq)

Create a function calcFreqList that does exactly the same with the following requirements:

  • the list is passed as the argument "arg1"
  • the function returns a dictionary that stores the frequency of each element

In [ ]:

 
# write your function here
def calcFreqList(arg1):
 # write your code here
 return ? # replace the question mark with your variable's name

Try the function. The expected outcome is (please note that the order my change):

  • "{'two': 2, 'three': 1, 'one': 3, 'four': 1}"

In [ ]:

# test the function here
print(calcFreqList(mylist))

Exercise 6.3 The following code calculates the frequency of elements in a list. In [ ]: mylist = ['one', 'two', 'three', 'one','four', 'two', 'one'] setp = set (mylist) freq = dict().fromkeys (setp, 6) for p in mylist: freq[p] += 1 print(freq) Create a function calcFreqList that does exactly the same with the following requirements: the list is passed as the argument "arg1" the function returns a dictionary that stores the frequency of each element In [ ]: # write your function here def calcFreqList(argi): # write your code here return ? # replace the question mark with your variable's name Try the function. The expected outcome is (please note that the order my change): "{"two: 2, 'three': 1, 'one': 3, 'four: 1}" In [ ]: # test the function here print(calcFreqList(mylist))

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!