Last active
October 7, 2019 18:30
-
-
Save ChaitanyaBaweja/d251489fdcfbd147eba3d450550d5e0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# finding frequency of each element in a list | |
from collections import Counter | |
my_list = ['a','a','b','b','b','c','d','d','d','d','d'] | |
count = Counter(my_list) # defining a counter object | |
print(count) # Of all elements | |
# Counter({'d': 5, 'b': 3, 'a': 2, 'c': 1}) | |
print(count['b']) # of individual element | |
# 3 | |
print(count.most_common(1)) # most frequent element | |
# [('d', 5)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment