I am converting some code from another language to python. That code reads a rather large file into a string and then manipulates it by array indexing like:
str[i] = 'e'
This does not work directly in python due to the strings being immutable. What is the preferred way of doing this in python ?
I have seen the string.replace() function, but it returns a copy of the string which does not sound very optimal as the string in this case is an entire file.
1 Answer