I'm trying to replace all spaces in the dictionary's keys with "_" the code is:
test_parameters = {
'Debug Properties': {'DUT WRT Dump': True, 'DUT WRT Tool': True, "DUT Preset": "Stater"},
'Attenuation Values': {'DUT To BTOE': '3'},
'BT Parameters': {'Connection Interval': '7.5', 'Traffic_Duration': '30'},
}
for group in test_parameters:
new_group_name = group.replace(" ", "_")
group_value = test_parameters.pop(group)
test_parameters.update({new_group_name: group_value})
for key in test_parameters[new_group_name]:
new_key_name = key.replace(" ", "_")
key_value = test_parameters[new_group_name].pop(key)
test_parameters[new_group_name].update({new_key_name: key_value})
the first nested dictionary 'Debug Properties' working fine, then when the code finish the last code line for 'DUT To BTOE' the for is failing with error "RuntimeError: dictionary keys changed during iteration"
how can I achieve this functionality?
Thanks