Created
September 17, 2025 01:19
-
-
Save rlcarrca/3332b026481ea7d130f2b1975fddaaee to your computer and use it in GitHub Desktop.
Return the most frequent item that appears in a 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
# returns the most frequent item that appears in the list: | |
def most_frequent(list): | |
return max(set(list), key = list.count) | |
numbers = [1,2,1,2,3,2,1,4,2] | |
x = most_frequent(numbers) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment