Temporarily change one entry in a supplied dictionary. Do not change unrelated entries.

Prototype: temporary_value(mapping, key, value) is a context-manager factory. Assume the key already exists. Set it to the supplied value during the block; yield the same mapping; restore the old value afterward, including after an exception. Do not suppress the body's exception.

Final: temporary_setting(mapping, key, value) has the same behavior but also handles an initially absent key: remove it on exit. Restore the original state of the selected key even if the body assigns or deletes that key. Preserve unrelated changes made by the body. Nested uses must restore in last-in, first-out order. Example: with settings={"mode": "light"}, a temporary "dark" value becomes "light" again afterward. A missing key originally remains missing afterward. No thread safety is required.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.