Codington
0 of 6 problems solved • 0%

Exercise prompt

Read a Feature Switch

Example

A dictionary can supply a default for a missing field while preserving a stored false value.

import json options = json.loads('{"hints": false}') print(options.get("hints", True)) # False print(options.get("sound", True)) # True

The default only applies when the key is absent. Handle the outer container in the same way when settings are nested.

Your task

Implement feature_enabled(text, name, default). Decode a JSON object whose optional features field maps feature names to booleans. Return the stored boolean for the named feature, or the supplied boolean default if the field or feature is absent.

feature_enabled('{"features":{"map":false}}', "map", True) # False