Skip to content

Instantly share code, notes, and snippets.

@Shogun89
Last active July 5, 2019 05:34
Show Gist options
  • Save Shogun89/e95964b42cf28ba7faea3bf3ceeed088 to your computer and use it in GitHub Desktop.
Save Shogun89/e95964b42cf28ba7faea3bf3ceeed088 to your computer and use it in GitHub Desktop.
def find_max(my_list):
my_set = set(my_list)
my_dict = {}
for item in my_set:
my_dict[item] = my_list.count(item)
my_max = max(my_dict.keys(), key=(lambda k: my_dict[k]))
return my_max
l = ['Apple', 'Orange', 'Banana', 'Peach', 'Peach']
s = set(l)
my_dict ={}
for j in s:
my_dict[j] = l.count(j)
key_max = max(my_dict.keys(), key=(lambda k: my_dict[k]))
@s-o-r-r-o-w
Copy link

s-o-r-r-o-w commented Jul 5, 2019

from collections import Counter
counter = Counter("here's a string") # or pass a list (or any iterable or mapping)
counter.most_common(1) # [('e', 2)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment