question 72 Dictionaries & Sets · easy
Tidying settings keys crashes
An app reads its settings from a file that people edit by hand, so the keys arrive with stray spaces and random capitals. This program should print the settings with every key stripped and in lower case. The values must stay exactly as they were. It stops with RuntimeError: dictionary changed size during iteration, and even the idea behind it is incomplete. Fix it.
Input
settings, a dictionary whose keys may have spaces at the ends and capital lettersPrintsa dictionary with the same values under cleaned keys (stripped, lower case), in the original order
Clashif two keys clean to the same name, the later one's value wins
Examplesthe starter's settings →
{'theme': 'Dark', 'language': 'en', 'timezone': 'UTC'}Expected output1 line
- 1{'theme': 'Dark', 'language': 'en', 'timezone': 'UTC'}