I have a task to replace in each element of the list (with the help of the function replace()
) one substring for another. I do this by iterating through each item in the list and replacing the substring in it with forloop.
array = ["one", "two", "three", "four", "five"] for a in array: a = a.replace("o", "zzzz") print(a) print(array)
However, when displaying each element of the list in a loop and then outputting the entire list separately, I see that the list has not changed:
zzzzne twzzzz three fzzzzur five ['one', 'two', 'three', 'four', 'five']
So why the list does not change?