Modifying an element of a list in a function


Oops, try again. list_function([1, 2]) returned 5 instead of [1, 5] is the error msg.

def list_function(x):
    return x[1]

n = [3, 5, 7]
print list_function(n)


Change list_function so that:

Add 3 to the item at index one of the list.
Store the result back into index one.
Return the list.


do you return the list?


Hi uzumakinaruto99!

After looking throughout the forums, I noticed that the issue that you have is simply..

"return x[1]" should be "return x"

That should let you go on to the next lesson :slight_smile:


No it doesn't really solve the problem.


you reply to raidedvillager, with a quote of uzumakinaruto99 and "it" doesn't solve the problem, what is "it"? What is your question? Or is a question?


The above line of rectification was my response, the suggestion didn't work in my case.


But the suggestion is for uzumakinaruto99 code, not yours? You might have a different problem altogether. By responding that this solution doesn't work for you, without any further details is very confusing. Do you still have a problem? If so, please make a new topic so we can help.


Thank you @raidedvillager and @stetim94