I'm having issues with editing elements in a list in Python, I've got the following code:
mylist = ["one", "day", "soon"]
for x in mylist:
x = "New word"
mylist2 = ["a", "b", "c"]
for x in mylist2 :
mylist2[mylist2.index(x)] = "Woo"
The problem is that when you iterate with
for x in mylist and then assign a value to
x, you are creating a new variable called
x and that is what you are printing. You cannot change the list in that way, only by iterating like this:
for i in range(len(mylist)): mylist[i] = "New word"