MCPcopy Index your code
hub / github.com/RustPython/RustPython / sum_dict_key

Function sum_dict_key

extra_tests/custom_text_test_runner.py:137–142  ·  view source on GitHub ↗

Sum together all values matching a key given a passed dict

(d, key, cast_type=None)

Source from the content-addressed store, hash-verified

135
136
137def sum_dict_key(d, key, cast_type=None):
138 """Sum together all values matching a key given a passed dict"""
139 return reduce(
140 (lambda x, y: x + y),
141 [eval("%s(x['%s'])" % (cast_type, key)) if cast_type else x[key] for x in d],
142 )
143
144
145def case_name(name):

Callers 1

Calls 2

reduceFunction · 0.90
evalFunction · 0.50

Tested by

no test coverage detected