Key Exists vs Truthy Value

Easy ⏱ 8 min 83% acceptance ★★★★★ 4.9
Write a function describe_flag(settings, key) that inspects dict settings. Return "missing" if key is not a key in settings at all. Return "present but falsy" if the key exists but its value is falsy (e.g. 0, "", False, None). Return "present and truthy" otherwise. This distinguishes key existence from truthiness of the value.

Examples

Example 1
Input
describe_flag({'debug': False}, 'debug')
Output
'present but falsy'
Explanation

debug is a key, but False is falsy.

Example 2
Input
describe_flag({}, 'debug')
Output
'missing'
Explanation

debug is not a key at all.

Example 3
Input
describe_flag({'debug': True}, 'debug')
Output
'present and truthy'
Explanation

debug is a key with a truthy value.

Constraints

  • Must distinguish absence from a falsy present value — do not just use `if settings.get(key):`.

Topics

Dictionariesexistence vs falsy values

Companies

OracleSAP-style client

Hints

Hint 1

Check `key not in settings` first.

Hint 2

Then check `bool(settings[key])`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.