Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
suppress ZeroDivisionError caused by eval solution in Creative category for Aggregate by Operation by Phil15
from contextlib import suppress
def aggr_operation(data: list[tuple[str, int]]) -> dict[str, int]:
res = {}
for key, value in data:
op, key = key[0], key[1:]
if key:
with suppress(ZeroDivisionError):
if n := value if op == '=' else eval(f'{res.pop(key, 0)}{op}{value}'):
res[key] = n
return res
Aug. 20, 2022
Comments: