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

Popular posts from this blog

ERR: error parsing query: found influx, expected SELECT, DELETE, SHOW, CREATE, DROP, EXPLAIN, GRANT, REVOKE, ALTER, SET, KILL at line

How to get Full URL or get absolute url In Django

How To Convert Html File/URL/String Into Image Using Python