Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

String Manipulation or Data Parsing

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

Your question is String Manipulation or Data Parsing. 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

IBM Instana alert events may include compact label strings such as service=checkout;severity=critical;region=us-east. Implement a function that parses this string into a dictionary of label names and values.

Each pair is separated by a semicolon, and the key and value are separated by the first equals sign. Remove leading and trailing whitespace from each pair, key, and value. Values may contain additional equals signs, which must remain part of the value.

Formal Specification

Given a non-empty string labels, return a dictionary mapping each label key to its string value. Every input pair contains exactly one non-empty key. Keys are unique, and the input does not contain empty pairs.

Constraints

  • 1 <= len(labels) <= 10^5
  • Each pair is separated by exactly one semicolon
  • Each pair contains a non-empty key and an equals sign
  • Keys are unique
  • Values may be empty and may contain equals signs, but not semicolons

Function Signature

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