Relational table join
Your task
Implement a relational join of two tables given as lists of dicts. Join 'left' and 'right' on the column name 'key' (present in both). For 'inner' join, emit one merged row per matching pair; for 'left' join, also emit left rows with no match, filling right-only columns with the string 'NULL'. Merged rows contain the left row's fields plus the right row's fields, with right values winning on any shared non-key column name. Preserve left-table order, and for a given left row preserve right-table order of its matches. Return the list of merged dicts.
Examples
join_tables(left: list[dict], right: list[dict], how: str) -> list[dict]Example 1
Input
join_tables([{"key": 1, "name": "a"}, {"key": 2, "name": "b"}], [{"key": 1, "city": "NY"}, {"key": 1, "city": "LA"}], "inner")Output
| key | name | city |
|---|---|---|
| 1 | a | NY |
| 1 | a | LA |