python counter least common

Solutions on MaxInterview for python counter least common by the best coders in the world

showing results for - "python counter least common"
Salvatore
02 Jul 2017
1from collections import Counter
2data_list = [1,1,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4]
3least_common = Counter(data_list).most_common()[-1]
4print(least_common)
5# The number 1 appears 2 times
6(1, 2)
Louisa
17 Mar 2017
1import collections
2c = collections.Counter(a=1, b=2, c=3)
3n = 2
4
5print c.most_common()[:-n-1:-1]Output[('a', 1), ('b', 2)]
6