How to Find Max Reaped Values In List using Python
1)
Using counter we can get a count of list elements in dictionary formate
from collections import Counter
List = [2, 1, 2, 2, 1, 3]
print(Counter(List))
output- {2: 3, 1: 2, 3: 1}
2) Using Max and Set method
List = ['Cat','Dog','Dog','cat','cat']
res = max(set(List), key = List.count)
print(res)
3) We can find using Mode
import statistics
from statistics import mode
List = [2, 1, 2, 2, 1, 3]
print(mode(List))
Comments
Post a Comment