Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicating Records Function

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Deduplicating Records Function. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Hilton Grand Vacations data workflows may receive repeated reservation or member records from multiple source files. Write a function that removes duplicate records based on a specified unique identifier while preserving the order in which identifiers first appear.

Keep the first record encountered for each identifier and discard every later record with the same identifier. The input records are not modified.

Formal Specification

Implement deduplicate_records(records, identifier_key).

  • records is a list of dictionaries.
  • identifier_key is a string naming the identifier field present in every record.
  • The identifier value is an integer or string and is hashable.
  • Return a new list of dictionaries containing only the first record for each identifier.
  • Preserve the original dictionary objects and their first-occurrence order.

Constraints

  • 0 <= len(records) <= 100,000
  • Every record contains identifier_key
  • Identifier values are integers or strings and are hashable
  • The input list and its dictionaries must not be modified

Function Signature

def deduplicate_records(records, identifier_key):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output