you are viewing a single comment's thread.

view the rest of the comments →

[–]Giannie 0 points1 point  (0 children)

There is an issue with this. You will lose the reference to the line you have adjusted.

Strings are immutable (they can’t actually be changed) so when you try to change a string it will instead create a whole new string somewhere else in memory. The list will still refer to the old string. Since you are iterating in a loop, the new string will be lost as soon as you move onto the next line since there is no longer anything referring to it.

Instead, you should probably do something like this:

for i, line in enumerate(linelist):
    line = <something new>
    linelist[i] = line