Program 12: Count Frequency of Elements Using Dictionary
हिंदी में: Frequency का अर्थ है किसी element का List में कितनी बार आना। Dictionary का उपयोग करके प्रत्येक element की frequency count की जा सकती है।
English: Frequency is the number of times an element occurs in a list. A dictionary can store the frequency of each element.
Code:
numbers = [10, 20, 10, 30, 20, 10]
frequency = {}
for num in numbers:
if num in frequency:
frequency[num] += 1
else:
frequency[num] = 1
print("Frequency:", frequency)
Output:
Frequency: {10: 3, 20: 2, 30: 1}