3 ms·
def least_common(c, n=None): key = operator.itemgetter(1) if n is None: return sorted(c.items(), key=key) return heapq.nsmallest(n, c
by d0mine 16y ago
def least_common(c, n=None):
key = operator.itemgetter(1)
if n is None:
return sorted(c.items(), key=key)
return heapq.nsmallest(n, c.items(), key=key)
It has the same efficiency as Counter.most_common().