Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
Start free
Group Components into Parts and Assemblies
00:00
5 left

Group Components into Parts and Assemblies

EasyPython

Problem

A 3DEXPERIENCE frontend receives component records in a flat JSON object, but the interface needs separate lists for parts and assemblies. Implement a function that transforms the input into this grouped output format while preserving the original order within each group.

Formal Specification

Implement transform_components(data). The input is a dictionary with a components key containing a list of dictionaries. Each component has:

  • id: a unique string
  • name: a display name string
  • type: either "part" or "assembly"
  • status: a string that should not appear in the output

Return a dictionary with two keys: parts and assemblies. Each output item must contain only id and label, where label is copied from name. Components must remain in their original relative order within each group.

Examples

Example 1

Input: {"components": [{"id": "P1", "name": "Bracket", "type": "part", "status": "Released"}, {"id": "A1", "name": "Chassis", "type": "assembly", "status": "In Work"}]}

Output: {"parts": [{"id": "P1", "label": "Bracket"}], "assemblies": [{"id": "A1", "label": "Chassis"}]}

The records are grouped by type and renamed for the frontend view model.

Example 2

Input: {"components": [{"id": "A2", "name": "Door", "type": "assembly", "status": "Released"}, {"id": "P2", "name": "Handle", "type": "part", "status": "Draft"}, {"id": "P3", "name": "Bolt", "type": "part", "status": "Released"}]}

Output: {"parts": [{"id": "P2", "label": "Handle"}, {"id": "P3", "label": "Bolt"}], "assemblies": [{"id": "A2", "label": "Door"}]}

Constraints

  • 1 <= len(data["components"]) <= 10^5
  • Every component contains id, name, type, and status
  • type is either "part" or "assembly"
  • IDs and names are non-empty strings

Function Signature

def transform_components(data):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.