xxxxxxxxxx
from collections import Counter
data_list = [1,1,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4]
least_common = Counter(data_list).most_common()[-1]
print(least_common)
# The number 1 appears 2 times
(1, 2)
xxxxxxxxxx
from collections import Counter
list_of_words = ['Cars', 'Cats', 'Flowers', 'Cats', 'Cats', 'Cats']
c = Counter(list_of_words)
c.most_common(1)
print("", c.most_common(1))
xxxxxxxxxx
import collections
c = collections.Counter(a=1, b=2, c=3)
n = 2
print c.most_common()[:-n-1:-1]Output[('a', 1), ('b', 2)]
xxxxxxxxxx
from collections import Counter
seq = [7, 13, 42, 9, 26, 16, 47, 31, 29, 2, 15, 12, 18, 44,
3, 28, 36, 29, 16, 15, 42, 24, 8, 32, 34, 7, 22, 1, 39, 46, 29, 31,
48, 46, 4, 17, 41, 17, 6, 44, 19, 15, 44, 8, 40, 17, 10, 2, 45, 7, 50,
49, 34, 20, 9, 31, 3, 39, 25, 13]
seq1 = Counter(seq).most_common()[:-len(seq)-1:-1]
# generate least common number list
print(seq1)