Python does not allow string to be modified via indexed assignment. For example,
a = "hello"; a = "x" will produce a
TypeError: 'str' object does not support item assignment error. Grr!
The following one-liner
stridxrep() can be used if the need ever arises:
a = "hello" # Python doesn't allow the following: # a = "x" # A 'string index replace' function. stridxrep = lambda s, i, r: "".join([(s[x] if x != i else r) for x in …