Complete worked example
python
def inspect_example(rows):
latest = {}
for row in rows:
identity = row['id']
previous = latest.get(identity)
if previous is not None and row['version'] == previous['version'] and row['amount_cents'] != previous['amount_cents']:
raise ValueError('conflicting payload for the same version')
if previous is None or row['version'] > previous['version']:
latest[identity] = dict(row)
return [latest[key] for key in sorted(latest)]- Reasoning
- For each row, the program looks up the current retained record. A missing identity or strictly newer version replaces that record with a copied dictionary. A matching version is checked for incompatible payload. Older versions leave the retained record unchanged, and the report returns identities in sorted order.