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
Start free
Consume an API and Output CSV
00:00
5 left

Consume an API and Output CSV

MediumPython

Problem

Consume an API and convert to CSV file.

Asked in the technical interview stage. Practical coding task in the Andela technical interview.

Implement a deterministic, testable version without making network requests. The input is an ordered list of API page objects, each containing an items array of flat JSON records. Return one CSV string. Build the header from keys in first-seen order across all records, leave missing values empty, and correctly escape commas, quotes, and newlines using standard CSV rules.

Signature: def api_pages_to_csv(pages):

Output: A CSV string with one header row and one row per record. Use line endings and return an empty string when there are no records.

Constraints

  • pages is an ordered list of page objects
  • Each page contains an items list
  • Each item is a flat JSON object with string keys
  • There can be up to 10^5 total records and 50 columns
  • Values are strings, numbers, booleans, or null
  • Return an empty string when all pages contain no records

Function Signature

def api_pages_to_csv(pages):
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
CodePython 3
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.