Write a program to create a dictionary from an existing list of
numbers. The dictionary will have every element of the list as key
and the frequency of the elements as value
Answers
Answered by
8
def create_freq_dict(l):
obj = {}
for n in l:
if n in obj:
obj[n] += 1
else:
obj[n] = 1
return obj
l = [2, 5, 1, 5, 2, 1, 3, 3, 4, 4, 5]
print(create_freq_dict(l))
Similar questions