Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimizing Python Data Transformations
00:00
5 left

Optimizing Python Data Transformations

MediumPython

Problem

Write an optimized function to handle large-scale data transformation in Python.

Implement transform_records(records, mapping) to return a list of transformed dictionaries. records is a list of dictionaries, and mapping maps each output key to a source key. Preserve record order, include only source fields that exist, and return an empty dictionary when no mapped source fields exist.

Constraints

  • 0 <= len(records) <= 5,000
  • records is a list of dictionaries
  • mapping is a dictionary from output field names to source field names
  • Each key and value is a string or JSON-compatible primitive

Function Signature

def transform_records(records, mapping):
Interviewer

Your question is Optimizing Python Data Transformations. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.