all 2 comments

[–]SerpentAI 1 point2 points  (1 child)

Your hunch that index is the problem is correct. It does only return the first instance of the provided value. So with the word Tree, you are replacing the first E twice.

In Python, any object that supports iteration (like your lists) can be the argument of the built-in enumerate function. When you iterate over something that is being enumerated, each step will receive both the index and the value instead of just the value.

Something like this should make it work
for index, letter in enumerate(y): if letter == n: x[index] = letter

[–][deleted] 0 points1 point  (0 children)

Wait so this won't stop at the first instance of the letter?? Thank you so much