def settlement(rows): seen = set() total = 0 for ident, amount, approved in rows: if not isinstance(ident, str) or not ident or ident in seen: raise ValueError("invalid or duplicate obligation") if approved is not True or type(amount) is not int or not 0 < amount <= 10**9: raise ValueError("unapproved obligation") seen.add(ident) total += amount if total > 10**9: raise ValueError("batch limit") return total assert settlement([("a", 100, True), ("b", 200, True)]) == 300 try: settlement([("a", 100, True), ("a", 100, True)]) except ValueError: pass else: raise AssertionError("duplicate accepted")