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})
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())))
Comments
Leave a comment