Sii Poland

SII UKRAINE

SII SWEDEN

Back

Sii Poland

SII UKRAINE

SII SWEDEN

Back

24.11.2026

Python Developer recruitment – an example technical task

24.11.2026

Rekrutacja na Python Developera – przykładowe zadanie techniczne

Wanting to start my career path as a Python programmer in the age of AI, I wondered what the point of solving a task “on a piece of paper” during recruitment is.

In this article, I will share a task I came across. We will go through its development process step by step and learn about several properties of the Python language. If you are interested in the topic, I invite you to read my previous article in a similar convention (Recruitment for a Junior Python Developer – an example of a technical task).

Task: search for text in text

We take the search engine on our drawing board – finding a string of characters in another string, but at the output we expect a list of string indexes starting at the first character of the searched word.

For the purposes of this task, I will simplify the nomenclature: a word is a searched string, a sentence is a string of characters in which we search for the aforementioned word.

Below is an example of a function call with the expected result:

>>> search('aa', 'maakkaanaakka')
[1, 5, 8]

I used Python version 3.x to solve the problem.

At first glance, the task seems easy, especially when AI can generate the correct solution in seconds. In practice, however, a technical interview is often not about the result itself, but about how the problem is analysed, the decision is justified, and the solution is adapted to changing requirements. Therefore, let’s go through the next approaches to do just that.

Basic approach

Since we are working with strings, which are a built-in type, let’s see whether the documentation can solve this problem for us.

On the docs.python.org website, we find a family of find methods. Unfortunately, they solve our problem only halfway, because they only return the first occurrence of the word. After a long contemplation, we conclude that further considerations in this direction may bring the expected result, but it would be convoluted, to say the least.

def search001(word, sentence):
    """
    Return tha list of index of a substring found in string

    >>> search001('aa', 'makkaanada')
    [4]

    >>> search001('ad', 'makkaanada')
    [7]

    >>> search001('an', 'makkaanada')
    [5]
    """
    return [sentence.find(word)]

An ambitious approach – a regular expression

It seems intuitive that if we want to find a word in a sentence, using a regular expression (RegEx) will settle the matter. We import the appropriate library and get to work.

To quote a classic:

If you want to solve your problem with a regular expression, you now have two problems: solving the problem and creating a valid regular expression.

def search002(word, sentence):
    """
    Return tha list of indexs of a substring found in string

    >>> search002('aa', 'makkaanada')
    [4]

    >>> search002('ad', 'makkaanada')
    [7]

    >>> search002('an', 'makkaanada')
    [5]
    """
    return [re.search(word, sentence).span()[0]]

And everything would be fine if we were looking for only the first occurrence of a word in a sentence.

After searching in your favourite AI for a while, by inserting the code above, we found two things:

Below is the code, returning all the indexes found with their corresponding tests:

def search003(word: str, sentence: str) -> list:
    """
Return tha list of indexs of a substring found in string

    >>> search003('aa', 'maakkaanaakka')
    [1, 5, 8]

    >>> search003('kk', 'maakkaanaakka')
    [3, 10]

    >>> search003('ak', 'maakkaanaakka')
    [2, 9]
    """
    return [match.start() for match in re.finditer(word, sentence)]

Or maybe we will use a Python property?

Strings in Python can break a sentence into “segments” of word length on the fly and compare them directly.

def search004(word: str, sentence: str):
    """
    Return tha list of indexes of a substring found in string

    >>> search004('aa', 'maakkaanaakka')
    [1, 5, 8]

    >>> search004('kk', 'maakkaanaakka')
    [3, 10]

    >>> search004('ak', 'maakkaanaakka')
    [2, 9]
    """
    response = []
    word_len = len(word)
    for i in range(len(sentence) - word_len + 1):
        if (word == sentence[i:i+word_len]):
            response.append(i)
    return response

Plot twist – change in requirements

All solutions based on regular expressions or built-in functions such as ‘str.find()’ require the results to be stored in memory. In our case, this is not optimal, because the searched texts can be very large, reaching hundreds of megabytes or even several gigabytes. Therefore, instead of returning a list of all matches, it is better to return a generator that yields results on the fly and uses much less memory.

We can convert our last solution in a very easy way.

def search005(word: str, sentence: str):
    """
    Return tha list of indexes of a substring found in string

    >>> list(search005('aa', 'maakkaanaakka'))
    [1, 5, 8]

    >>> list(search005('kk', 'maakkaanaakka'))
    [3, 10]

    >>> list(search005('ak', 'maakkaanaakka'))
    [2, 9]
    """
    word_len = len(word)
    for i in range(len(sentence) - word_len + 1):
        if (word == sentence[i:i + word_len]):
            yield i

More optimisation, more optimisation!

To achieve the highest possible efficiency and answer the problem as precisely as possible, let’s check whether we can solve it by adapting the above method and using only character comparisons.

Let’s iterate over the signs in our sentence; if the character at a given position equals the first sign of the word, we compare the subsequent characters of the word and the sentence. As soon as we find a character that doesn’t match, we move on to the next step in the sentence iteration.

def search006(word: str, sentence: str):
    """
    Return a generator of indexs of a substring found in string

    >>> list(search006('aa', 'maakkaanaakka'))
    [1, 5, 8]

    >>> list(search006('kk', 'maakkaanaakka'))
    [3, 10]

    >>> list(search006('ak', 'maakkaanaakka'))
    [2, 9]

    >>> list(search006('au', 'maakkaanaakka'))
    []

    >>> list(search006('ana', 'maakkaanaakka'))
    [6]

    >>> list(search006('ana', 'maannakkaanaakka'))
    [9]

    """

    word_len = len(word)
    for i in range(len(sentence) - word_len + 1):
        for j in range(word_len):
            if (sentence[i+j] == word[j]):
                if (j == word_len-1):
                    yield i
            else:
                break

Let’s summarise what we know

  • iteration over the array of elements – the ‘range’ function,
  • the string is an array,
  • using a method that counts characters in a string,
  • cutting out board elements,
  • regular expressions as a library,
  • the ability to create generators and use them,
  • knowledge of the technique of creating tests in documentation,
  • the ability to modify the solution when the requirements of the problem change.
Blog SzkoleniaDesktop  - Python Developer recruitment – an example technical task

Training in IT, business, and soft skills

Learn from experts who implement digital solutions for leading companies every day.

Trainings offering

Conclusion

As you go through the successive versions of the solution, it is easier to understand why similar tasks continue to appear during recruitment. They do not only test the knowledge of syntax or ready-made functions, but above all the way of thinking, the analysis of compromises and the ability to develop the solution as the requirements change.

The code for our struggle is available on GitHub.

It’s hard to say whether demonstrating such knowledge and skills will be enough to get the coveted Python Developer position.

Certainly, the solution to the task shows analytical skills, approaches the problem from different perspectives, and demonstrates knowledge of Python basics. And it won’t hurt! Training on such basic examples and developing and documenting the code in the repository will be an additional advantage.

5/5
Rating
5/5

Leave a comment

Your email address will not be published. Required fields are marked *

You might also like

SUBSCRIBE AND DON'T FALL BEHIND

Blog Newsletter

Show results
Join us Contact us

Ta treść jest dostępna tylko w jednej wersji językowej.
Nastąpi przekierowanie do strony głównej.

Czy chcesz opuścić tę stronę?