MCPcopy Create free account
hub / github.com/ActiveState/code / counts

Method counts

recipes/Python/52231_Count_items_sort/recipe-52231.py:7–15  ·  view source on GitHub ↗

Returns list of keys, sorted by values. Feed a 1 if you want a descending sort.

(self,desc=None)

Source from the content-addressed store, hash-verified

5 count = self.dict.setdefault(item,0)
6 self.dict[item] = count + 1
7 def counts(self,desc=None):
8 '''Returns list of keys, sorted by values.
9 Feed a 1 if you want a descending sort.'''
10 i = map(lambda t: list(t),self.dict.items())
11 map(lambda r: r.reverse(),i)
12 i.sort()
13 if desc:
14 i.reverse()
15 return i
16
17if __name__ == '__main__':
18

Callers 1

recipe-52231.pyFile · 0.45

Calls 5

mapFunction · 0.85
listClass · 0.85
itemsMethod · 0.45
reverseMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected