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.
Implement transform_components(data). The input is a dictionary with a components key containing a list of dictionaries. Each component has:
id: a unique stringname: a display name stringtype: either "part" or "assembly"status: a string that should not appear in the outputReturn 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.
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"}]}
def transform_components(data):