I\'m making a function to modify the elements in a list, but it doesn\'t change all the way through... My function is:
def modifyValues(l):
for x in l:
When you iterate through the loop, you are iterating the loop elements and not the indexes.
You need to use enumerate
to get the indexes along with the values.
A small demo can be
def modifyValues(l):
for i,x in enumerate(l): # Use enumerate here.
if x == 1:
l[i] = 'a'
elif x == 2:
l[i] = 'b'
elif x == 3:
l[i] = 'c'
print (l)
Output
['a', 'b', 'c', 'b', 'c', 'a', 'b', 'b']