MCPcopy Index your code
hub / github.com/clips/pattern / most_common

Method most_common

pattern/metrics.py:41–46  ·  view source on GitHub ↗

Returns a list of the n most common (element, count)-tuples.

(self, n=None)

Source from the content-addressed store, hash-verified

39 self[k] = self.get(k, 0) + 1
40
41 def most_common(self, n=None):
42 """ Returns a list of the n most common (element, count)-tuples.
43 """
44 if n is None:
45 return sorted(self.items(), key=itemgetter(1), reverse=True)
46 return nlargest(n, self.items(), key=itemgetter(1))
47
48 def copy(self):
49 return Counter(self)

Callers 1

__repr__Method · 0.95

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected