Predict the output
What does the redactor print?
SENSITIVE = {"authorization", "password", "cookie"}
def redact(h: dict[str, str]) -> dict[str, str]:
return {k: "[redacted]" if k.lower() in SENSITIVE else v
for k, v in h.items()}
print(redact({"Authorization": "Bearer abc", "Accept": "json"}))Hint 1 of 1
What does k.lower() return?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A {'Authorization': '[redacted]', 'Accept': 'json'}
Correct. Matching is case-insensitive via lower().
HTTP header names aren't case-sensitive, so the redactor lowercases each key before checking the deny list. Authorization matches and its value is replaced; Accept passes through.
Why not the others?
- B
{'Authorization': 'Bearer abc', 'Accept': 'json'}. lower() makes 'Authorization' match. - C
{'Accept': 'json'}. Keys are kept; values are replaced. - D
{'Authorization': '[redacted]', 'Accept': '[redacted]'}. Accept isn't sensitive.