runtime
72 / 500
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.

Inputsettings, a dictionary whose keys may have spaces at the ends and capital letters
Printsa 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. 1{'theme': 'Dark', 'language': 'en', 'timezone': 'UTC'}

Loading your progress…

Tidying settings keys crashes — Python practice · Runtime