Replace single character at given position

Roberto Bonvallet Roberto.Bonvallet at
Wed Sep 20 16:12:40 CEST 2006

bearophileHUGS at wrote:
> Martin Kulas:
>> Are there better (faster) ways to achieve my goal?
>> I have looked through the methods of type ``string''
>> but I have not found any appropriate method or function.
> A second way is to use a list of strings with len=1. Like this:
>>>> idx = 1
>>>> s1 = "pxthon"
>>>> l1 = list(s1)
>>>> l1[idx] = 'y'
> ... more processing on the elements of l1, then at the end:
>>>> "".join(l1)
> 'python'

There is a MutableString class that would be a better approach:

Anyway, I bet that what Martin wants to do can be done by using only string
methods :)
Roberto Bonvallet

More information about the Python-list mailing list