That python dicts have an upsert method: https://docs.python.org/3/library/stdtypes.html#dict.setdefault