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
Parse Player Stats to JSON
00:00
5 left

Parse Player Stats to JSON

MediumPython

Problem

Write a function to parse a complex raw string containing player statistics and format it into a structured JSON object.

The input contains player records separated by ;, fields separated by |, and statistics stored as comma-separated key:value pairs after stats=. Return a Python dictionary with a players array, converting player_id and integer statistics to integers and decimal statistics to floats. Inputs are valid and contain player_id, name, team, and stats for every player.

Constraints

  • 1 <= number of player records <= 10^4
  • Each record contains player_id, name, team, and stats fields
  • Fields are separated by | and records are separated by ;
  • Statistics are separated by commas and use key:value format
  • player_id and statistic values are valid integers or decimal numbers
  • Input does not contain escaped delimiters or malformed fields

Function Signature

def parse_player_stats(raw):
Interviewer

Your question is Parse Player Stats to JSON. 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.