Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner: defaultdict solution in Clear category for Convert and Aggregate by Stensen
from collections import defaultdict
def conv_aggr(data: list[tuple[str, int]]) -> dict[str, int]:
d = defaultdict(int)
for i, j in data:
d[i] += j
if not i or not d[i]: d.pop(i)
return d
Sept. 30, 2022
Comments: