educative.io

Why do we need the index parameter?

What’s wrong with:

def replace(array):
if array == []:
    return []
if array[0] < 0:
    array[0] = 0
return [array[0]] + replace(array[1:])

Hi @Patrick_Dennis,

This is Fatimah from Educative.

In response to your question, your code is absolutely correct! You have used list slicing operations instead of indexes as we have done in the lesson. The answer is absolutely valid and takes advantage of in-built capabilities. Whereas, the one we have shown is more generic and can be coded similarly in any other language as well.

We hope Educative has inspired to further your learning, and please drop us a note if you have any other questions or concerns.

Best Regards,
Fatimah Abdullah | Developer Advocate
Educative

1 Like