Tiny query engine
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.
Implement
run_query(rows: list[dict], spec: dict) → list[dict]Examples
in
[[{"id":1,"age":30,"name":"a"},{"id":2,"age":25,"name":"b"},{"id":3,"age":40,"name":"c"}],{"sort":["age","asc"],"filter":["age",">",26],"project":["name","age"]}]out[{"age":30,"name":"a"},{"age":40,"name":"c"}]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[{"id":1,"age":30,"name":"a"},{"id":2,"age":25,"name":"b"},{"id":3,"age":40,"name":"c"}],{"sort":["age","asc"],"filter":["age",">",26],"project":["name","age"]}][{"age":30,"name":"a"},{"age":40,"name":"c"}]not run yetsample