Truthy/Falsy Branching: Config Defaults

Medium ⏱ 12 min 61% acceptance ★★★★☆ 4.2
Write a function resolve_config(value, default) that returns default if value is "falsy" (e.g. None, 0, "", [], False) and returns value itself otherwise. This mimics how config loaders fall back to defaults without explicit is None checks.

Examples

Example 1
Input
resolve_config(0, 10)
Output
10
Explanation

0 is falsy, so the default is used.

Example 2
Input
resolve_config("", "guest")
Output
"guest"
Explanation

Empty string is falsy.

Example 3
Input
resolve_config("admin", "guest")
Output
"admin"
Explanation

"admin" is truthy, so it is kept.

Constraints

  • value can be any type.

Topics

Conditional Statementstruthy/falsy

Companies

IntelIBM

Hints

Hint 1

A plain `if not value:` covers all standard falsy values in Python.

Hint 2

Do not special-case each type individually — rely on Python's general truthiness rules.

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