Sum together all values matching a key given a passed dict
(d, key, cast_type=None)
| 135 | |
| 136 | |
| 137 | def 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 | |
| 145 | def case_name(name): |
no test coverage detected