Created
July 28, 2020 13:01
-
-
Save FerdinaKusumah/c2d1bc00c9ee8b7ab5d9d69571d6c3e7 to your computer and use it in GitHub Desktop.
[Python] Most Frequent in list
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
from collections import Counter | |
"""Find most frequent in list""" | |
arr = [1, 2, 3, 1, 2, 4, 6, 7, 3, 2, 3, 4] | |
cnt = Counter(arr) | |
# Counter({2: 3, 3: 3, 1: 2, 4: 2, 6: 1, 7: 1}) | |
"""Show only frequent in 2 times""" | |
print(cnt.most_common(2)) | |
# [(2, 3), (3, 3)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment