Question: Write the function frequency (numlist), which returns the most frequent items in numList and a dictionary containing the frequency count of each item In the

Write the function frequency (numlist), which returns the most frequent items in numList and a dictionary containing the frequency count of each item In the list. When multiple items have the same frequency, it will return the first item with that frequency.

The frequency in numList is the most common item. You can assume that numList is non-empty Python List, but you cannot make assumptions about the contents of the list. You can use count Method, but it is not allowed to use any other Python libraries (such as Counter, mode, etc.), or Use str() to convert the data to a string.

Example:

>>> frequency([3, 7, 5, 5, 7, 7, 5])

(7, {3: 1, 7: 3, 5: 3})

>>> frequency([3, '7', 5, 5.5, '7', 7, 5.5, 'a', 3, 'a', 'a', 'A'])

('a', {3: 2, '7': 2, 5: 1, 5.5: 2, 7: 1, 'a': 3, 'A': 1})

>>> answer=frequency([6, 5, 7, 7, 7, 5, 5, 5])

>>> answer[0]

5

>>> answer[1]

{6: 1, 5: 4, 7: 3}

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!