Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Extract Error Codes from Logs

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

Your question is Extract Error Codes from Logs. 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 list of log lines logs and a target severity string level, return all error codes that appear in lines matching that severity. A valid code appears as CODE=<value> where <value> consists of uppercase letters, digits, or underscores. Return each matching code once, in the order it is first found.

Constraints

  • 1 <= len(logs) <= 10^4
  • 0 <= len(logs[i]) <= 200
  • level is a non-empty uppercase string
  • A valid code contains only A-Z, 0-9, and _

Function Signature

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