← Lesson
Properties Beat String Equality
Joeven
Run
Reset
Python loads on first run
def props_ok(out, item): fails = [] if item.get("must_contain") and item["must_contain"] not in out["final"]: fails.append("fact") if item.get("exact_id") and out.get("order_id") != item["exact_id"]: fails.append("id") opened = set(item.get("opened") or []) for c in out.get("citations") or []: if c not in opened: fails.append("cite " + c) return fails paraphrase = { "final": "Refunds usually take 5-7 business days.", "order_id": "99", "citations": ["kb-44"], } item = { "must_contain": "5-7", "exact_id": "99", "opened": ["kb-44"], } print(props_ok(paraphrase, item)) print(props_ok({"final": "soon", "order_id": "99", "citations": ["evil"]}, item))
Run to execute this in your browser. Nothing is sent to a server.