Shell
·
發表于 4年以前
·
閱讀量:2598
此函數返回列表中出現頻率最高的元素。
def most_frequent(list):
return max(set(list), key = list.count)
numbers = [1, 2, 3, 2, 4, 3, 1, 3]
most_frequent(numbers) # 3