← Lesson
Coverage by Tag
Joeven
Run
Reset
Python loads on first run
def coverage(rows, need): counts = {} for r in rows: t = r.get("tag") or "untagged" counts[t] = counts.get(t, 0) + 1 missing = [] for tag, n in need.items(): if counts.get(tag, 0) < n: missing.append(tag) return {"counts": counts, "missing": missing, "ok": not missing} rows = [ {"id": "1", "tag": "billing"}, {"id": "2", "tag": "billing"}, {"id": "3", "tag": "safety"}, ] print(coverage(rows, {"billing": 2, "safety": 2, "injection": 2})) print(coverage(rows + [{"id": "4", "tag": "safety"}, {"id": "5", "tag": "injection"}, {"id": "6", "tag": "injection"}], {"billing": 2, "safety": 2, "injection": 2}))
Run to execute this in your browser. Nothing is sent to a server.