Counting the frequencies in a list using dictionary in Python || DSA #dsa #pythonprogramming

preview_player
Показать описание
Given an unsorted list of some elements(may or may not be integers), Find the frequency of each distinct element in the list using a dictionary.

Study resources:

Theory:

code:-
'''
Input : nums = [10, 20, 20, 10, 10, 20, 5, 20]
Output : 10 3
20 4
5 1
'''
def fun(nums):
dic = {}
for ele in nums:
if ele in dic:
dic[ele] = dic[ele] + 1
else:
dic[ele] = 1

for i in dic:
print(i,"=" , dic[i])


if __name__ == "__main__":
nums = [10, 20, 20, 10, 10, 20, 5, 20]
fun(nums)



#python #programming #coding #programmer #develope #coder
Рекомендации по теме
visit shbcf.ru