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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Extract a Nested Key From Arrays
00:00
5 left

Extract a Nested Key From Arrays

EasyPython

Problem

Würth Industry North America's VMI inventory data is grouped into nested arrays, where each element is a Python dictionary describing one catalog item. Given the nested records, an item identifier, and a dot-separated key path, return the corresponding value from the first matching object.

The key path may reference a top-level key, such as price, or nested dictionaries, such as dimensions.length. Return None if no object has the requested identifier or if any part of the key path is missing. Values may legitimately be None, and should be returned unchanged when the complete path exists.

Formal Specification

Implement get_catalog_value(records, item_id, key_path), where records is a list of rows, each row is a list of dictionaries. Every dictionary contains an item_id key, and identifiers are unique across all rows. Each key-path component refers only to dictionary keys.

Return the value at key_path for the object whose item_id equals item_id, or None when the object or path does not exist.

Constraints

  • 1 <= len(records) <= 10^4
  • Each row contains at least one dictionary
  • The total number of dictionaries is at most 10^5
  • 1 <= len(key_path.split(".")) <= 10
  • Every dictionary contains an item_id key
  • Item identifiers are unique across all rows

Function Signature

def get_catalog_value(records, item_id, key_path):
Interviewer

Your question is Extract a Nested Key From Arrays. 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.