Answers for "least occurred element from list in python"

0

least occurred element from list in python

# find less common
from collections import Counter
cnt = Counter()
for my_list in [5, 3, 7, 5, 3, 7, 3, 14, 12, 5, 6, 11, 3]:
 cnt[my_list] -= 1
print(cnt.most_common(5))
print(cnt)

# find most common
from collections import Counter
cnt = Counter()
for my_list in [5, 3, 7, 5, 3, 7, 3, 14, 12, 5, 6, 11, 3]:
 cnt[my_list] += 1
print(cnt.most_common(1))
print(cnt)

# find most common
my_list = [5, 3, 7, 5, 3, 7, 3, 14, 12, 5, 6, 11, 3]
print(max(set(my_list), key=my_list.count))
Posted by: Guest on September-08-2021

Code answers related to "least occurred element from list in python"

Python Answers by Framework

Browse Popular Code Answers by Language