PythiloLesson 5 of 8 · progress kept in this browser

Redact nested data without mutating it

Logging a whole decoded request can expose credentials nested below innocent-looking fields. Traverse dictionaries and lists recursively and replace values of sensitive keys. Matching key names without regard to case avoids obvious bypasses. Build new containers so redaction for logging does not silently change the data the application is processing.

data = {"profile": {"token": "secret"}}
print(data["profile"].keys())
Your task

Write redact(value). Recursively copy dicts and lists; replace values whose string key lowercases to password, token or secret with "[redacted]". Other scalar values stay unchanged. Do not modify the original.