10. modifying element of a list in a function


#1

which command would you use to update the list?


10. Modifying an element of a list in a function
#2

we can update an element in a list by doing:

your_list[index] = "new value"

#3

Well, you don't really use a "command" to update an element in a list, per se. You simply just set the element in the list equal (=) to the desired value. For instance:

x[0] = x[0] + 1

This would set the first item in the x list equal to itself plus 1. This can also be achieved using a shorthand:

x[0] += 1

#4

def list_function(x):
x[1] = x[1] + 3
return x[1]
n = [3, 5, 7]
print list_function(n)

so this still isnt working


#5

that is because you return the second item in the list, the instructions state that you should return the whole list


#6

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