Pybites Logo

Manipulate string decorator

Level: Advanced (score: 4)

Write a decorator called strip_range that replaces characters with dots. It takes a start and an end int argument that defines the range of characters to be replaced. These work like range, so start is inclusive and end is exclusive.

Best to illustrate with an example: decorating the gen_output function below, assuming text holds 'Hello world', it should convert it to 'Hel.. world' (= replace 0-indexed positions 3 and 4)

@strip_range(3, 5)
def gen_output(text):
    return text

See test_strip_range for more examples that have to pass in order to get credit. Good luck!

New to decorators? Check out our article and learning path.