Tiny query engine
Your task
Implement a tiny query engine. You are given rows (list of dicts with the same string keys) and a spec dict with three optional parts: 'filter' = [col, op, value] where op is one of '=','!=','>','<','>=','<=' (compare with Python's natural ordering of the stored values); 'project' = list of column names to keep, in that order; 'sort' = [col, 'asc'|'desc']. Apply filter, then sort (stable), then project. Return the resulting list of dicts. Any part may be absent, in which case it is skipped.
Examples
run_query(rows: list[dict], spec: dict) -> list[dict]Example 1
Input
run_query([{"id": 1, "age": 30, "name": "a"}, {"id": 2, "age": 25, "name": "b"}, {"id": 3, "age": 40, "name": "c"}], {"filter": ["age", ">", 26], "sort": ["age", "asc"], "project": ["name", "age"]})Output
| name | age |
|---|---|
| a | 30 |
| c | 40 |