What is wrong with my code? (Modifying an element of a list in a function)



. Your code looks a bit off.

Traceback (most recent call last):
File "python", line 6, in
File "python", line 3, in list_function
TypeError: list indices must be integers, not tuple

I expect the program to return the list.

def list_function(x):
    x[1] = x[1] +3
    return x[0,1,2]

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


x is a variable holding the list, so you can just return x


Got it now, thank you!:relaxed:


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