Deduplicate records using the values in key_columns as a composite key. Select one record per key according to strategy:
Regardless of strategy, order the output by the first appearance of each unique key. Return the selected records as a list of dictionaries without changing the input records.
Input: records = [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}], key_columns = ["id"], strategy = "first"
Output: [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}]
Explanation: The two records have different keys, so both remain.
Input: records = [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}, {"id": 1, "name": "Alice Smith", "email": "alice.s@test.com"}], key_columns = ["id"], strategy = "first"
Output: [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}]
Use tuple(record[column] for column in key_columns) as the composite key.
Store key order separately from grouped records, then select from each group.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: string
Deduplicate records using the values in key_columns as a composite key. Select one record per key according to strategy:
Regardless of strategy, order the output by the first appearance of each unique key. Return the selected records as a list of dictionaries without changing the input records.
Input: records = [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}], key_columns = ["id"], strategy = "first"
Output: [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}]
Explanation: The two records have different keys, so both remain.
Input: records = [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}, {"id": 1, "name": "Alice Smith", "email": "alice.s@test.com"}], key_columns = ["id"], strategy = "first"
Output: [{"id": 1, "name": "Alice", "email": "alice@test.com"}, {"id": 2, "name": "Bob", "email": "bob@test.com"}]
Use tuple(record[column] for column in key_columns) as the composite key.
Store key order separately from grouped records, then select from each group.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: string