Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Text Parsing Script
00:00
5 left

Text Parsing Script

MediumPython

Problem

Write a script that parses text from a file and prints some output when field X equals a given value.

Asked in the loop scripting round stage. Any language; described as simple.

Treat the file content as CSV with a header row. Implement filter_csv(text, field, value), returning matching records as a list of dictionaries. Preserve row order and compare field values exactly. The requested field is guaranteed to exist in the header.

Constraints

  • The input contains at most 1,000 data rows.
  • The first row is a valid CSV header.
  • The requested field exists in the header.
  • All records have the same fields.
  • Field values are compared as strings using exact equality.

Function Signature

def filter_csv(text, field, value):
Interviewer

Your question is Text Parsing Script. 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.