List manupulation in functions


#1

n = [3, 5, 7]

Add your function here

def list_extender(lst):
lst.append(9)
return list_extender(lst)
Oops, try again. list_extender([1, 2, 3, 4]) resulted in an error: maximum recursion depth exceeded.....Help


#2

You called your function in your return statement. Just return lst.

Calling the function in the return statement will make the computer run the function forever and ever (because you didn't tell it when to stop) causing the maximum recursion depth exceeded error.
This concept is known as recursion if you're interested to learn.


#3

When we return a call to the same function, it sets up a recursion and since there is no state change, it will be an infinite loop. Return just the list.


#4

can you tell me the full code... I am still not able to get answer it


#5

You're really close with your code. You just need to change the last line so that you are just returning your list and not returning your function call.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.