This simple code that simply tries to replace semicolons (at i-specified postions) by colons does not work:
for i in range(0,len(line)):
if (line[i]==";" and i in rightindexarray):
line[i]=":"
It gives the error
line[i]=":"
TypeError: 'str' object does not support item assignment
How can I work around this to replace the semicolons by colons? Using replace does not work as that function takes no index- there might be some semicolons I do not want to replace.
Example
In the string I might have any number of semicolons, eg "Hei der! ; Hello there ;!;"
I know which ones I want to replace (I have their index in the string). Using replace does not work as I'm not able to use an index with it.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…