def nlargest ( self , n = None ) : if n is None : return sorted ( self . counts ( ) , key = itemgetter ( 1 ) , reverse = True ) else : return heapq . nlargest ( n , self . counts ( ) , key = itemgetter ( 1 ) )
python counter get nlargest
List the n most common elements and their counts .
def nlargest(self, n=None):
		"""List the n most common elements and their counts.

		List is from the most
		common to the least.  If n is None, the list all element counts.

		Run time should be O(m log m) where m is len(self)
		Args:
			n (int): The number of elements to return
		"""
		if n is None:
			return sorted(self.counts(), key=itemgetter(1), reverse=True)
		else:
			return heapq.nlargest(n, self.counts(), key=itemgetter(1))