Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Unique Elements From Objects
00:00
5 left

Unique Elements From Objects

EasyPython

Problem

LSEG Workspace may return repeated instrument records when results are combined from multiple market-data sources. Given a list of dictionary objects and the name of a field that uniquely identifies an object, return the unique objects in their original order, keeping only the first object for each identifier.

Formal Specification

Implement unique_objects(objects, key), where objects is a list of dictionaries and key is a string. Every dictionary contains the specified key, and its value is hashable. Return a new list containing the first dictionary encountered for each distinct key value. Do not modify the input list.

Objects with different values in non-key fields are still duplicates when their values for key match. The returned dictionaries should be the original objects, not copies.

Constraints

  • 0 <= len(objects) <= 100,000
  • Each object contains the specified key
  • Each key value is hashable
  • The input list must not be modified
  • The first object for each identifier must be retained

Function Signature

def unique_objects(objects, key):
Interviewer

Your question is Unique Elements From Objects. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.