MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / sorted_counter

Function sorted_counter

src/summarycode/utils.py:46–60  ·  view source on GitHub ↗

Return a list of ordered mapping of {value:val, count:cnt} built from a `counter` mapping of {value: count} and sortedd by decreasing count then by value.

(counter)

Source from the content-addressed store, hash-verified

44
45
46def sorted_counter(counter):
47 """
48 Return a list of ordered mapping of {value:val, count:cnt} built from a
49 `counter` mapping of {value: count} and sortedd by decreasing count then by
50 value.
51 """
52
53 def by_count_value(value_count):
54 value, count = value_count
55 return -count, value or ''
56
57 summarized = [
58 dict([('value', value), ('count', count)])
59 for value, count in sorted(counter.items(), key=by_count_value)]
60 return summarized
61
62
63def get_resource_tallies(resource, key, as_attribute=False):

Callers 5

build_talliesFunction · 0.90
license_talliesFunction · 0.90
language_talliesFunction · 0.90
tally_codebase_key_filesFunction · 0.90
tally_codebase_by_facetFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected