Answer to Question #299754 in Python for Michael

Question #299754

Write a python function Count_Freq(A) which take a dictionary containing numbers. The function will return a dictionary containing key as a number and value as frequency defining how many times the number is repeating in the dictionary.

Note:

write a code without using counter function?

 

Example-1

Example-2

Input:

{'V': 10, 'VI': 10, 'VII': 40, 'VIII': 20, 'IX': 70, 'X': 80, 'XI': 40, 'XII': 20}

 

Output:

({10: 2, 40: 2, 20: 2, 70: 1, 80: 1})

Input:

{'V': 10, 'VI': 10, 'VII': 10, 'VIII': 10, 'IX': 20, 'X': 30, 'XI': 40, 'XII': 20}

Output:

({10: 4, 20: 2, 30: 1, 40: 1})



1
Expert's answer
2022-02-19T02:38:48-0500
def Count_Freq(A):
	frq_dict = {}
	for value in A.values():
		if value in frq_dict:
			frq_dict[value] += 1
		else:
			frq_dict[value] = 1
	return frq_dict


# testing function
print(Count_Freq(eval(input())))
print(Count_Freq(eval(input())))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS