Find the number having max count in list using Python

Find the number having max count in list:

def find_largest_count():
from collections import Counter
l=list(x for x in range(1,101))
L=[6,7,7,8,8,2,3,8,8,11,23,8,8,1,3,3,4,4,4]
#l.remove(55)
#most_common,num_most_common =Counter(L).most_common(1)[0]
#print most_common,num_most_common # 4, 6 times max(list(map(l2.count,l2)))
d={}
for x in L:
if x in d.keys():
d[x]+=1
else:
d[x]=1

(lk,lv)=(1,1)
for y in d.keys():
if lv < d[y]:
lv = d[y]
lk = y

print "Largest key is ",lk," And count is ",lv

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: