Skip to content

Instantly share code, notes, and snippets.

@rlcarrca
Created September 17, 2025 01:19
Show Gist options
  • Save rlcarrca/3332b026481ea7d130f2b1975fddaaee to your computer and use it in GitHub Desktop.
Save rlcarrca/3332b026481ea7d130f2b1975fddaaee to your computer and use it in GitHub Desktop.
Return the most frequent item that appears in a list
# 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