×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Matthew J_
Added: Jun 22, 2022 12:38 PM
Modified: Jun 22, 2022 1:27 PM
Views: 8
Tags: no tags
  1. # This method returns the most frequent element that appears in a list.
  2.  
  3. def most_frequent(list):
  4.         return max(set(list), key=list.count)
  5.  
  6.  
  7. numbers = [1, 2, 1, 2, 3, 2, 1, 4, 2]
  8. print(most_frequent(numbers))               # 2