Halo! Today I have to make a python program that meets these conditions:
-
Write a Python program that creates and print a dictionary that maps each element in a list to its corresponding frequency (how many times it occurs in the list).
-
The test should be case-sensitive. Therefore, “A” should not be considered the same element as “a”.
I think for today, I’m just going to make it short. Yea…
So this is how you do it-
ele = ['a', 'a', 'b', 'c', 'a', 'b']
dict = {}
for i in ele:
if i not in dict:
dict[i] = 1
else:
dict[i] = dict[i] + 1
print(dict)
Output -
{'a': 3, 'b': 2, 'c': 1}
The end…
o-o