Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse Key-Value String Map

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Parse Key-Value String Map. Start with the requirements on the right.

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.

Problem

Given a string data containing key-value pairs in the form key=value separated by semicolons, write a function that parses the string and returns a dictionary mapping each key to its value. Ignore malformed entries that do not contain exactly one = or that have an empty key. If a key appears multiple times, keep the last value.

Constraints

  • 0 <= len(data) <= 10^5
  • Keys and values may contain any characters except ;
  • A valid entry must contain exactly one = and a non-empty key

Function Signature

def parse_kv_data(data):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output