Extract Error Codes from Log Strings

PYTHON coding challenge · Difficulty: medium · Topic: Regular Expressions · +100 XP

Problem

Application logs mark failures with codes such as ERROR-1001. Write extract_error_codes(logs) that returns every error code in the order it appears, including several codes on one line. Return an empty list when there are none.

Example Input

The data below is already defined — do not redefine it.

`python

logs = [

"2024-01-01 INFO: Service started",

"2024-01-01 ERROR-1001: DB timeout",

"2024-01-02 ERROR-2345 and ERROR-6789 found",

"2024-01-03 INFO: All clear",

]

`

Expected Output

`

['ERROR-1001', 'ERROR-2345', 'ERROR-6789']

`

Notes

What this PYTHON challenge teaches you

“Extract Error Codes from Log Strings” is a medium-level PYTHON challenge focused on Regular Expressions. Working through it gives you hands-on practice with regex, log parsing, string manipulation — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. This is a Regular Expressions problem — review the matching python concept.
  2. Compare your output to the Expected Output — the columns and values must match. Row order is not graded; the rows themselves are, so return exactly this set and no extras.

Where this comes up

Variations of this problem have been reported in interviews at Netflix, Uber, DataDog. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.

How to practise it on PySpark.in

Open the challenge, write your Python code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related PYTHON challenges

Helpful resources

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The PYTHON environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated medium and covers Regular Expressions.

Solve this challenge free on PySpark.in