def flatten(my_dict): result = {} for key, value in my_dict.items(): if isinstance(value, dict): result.update(flatten(value)) else: result[key] = value return result