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
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

Your question is Consume an API and Output CSV. 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.