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]==\"
You can do this:
string = "this; is a; sample; ; python code;!;" #your desire string result = "" for i in range(len(string)): s = string[i] if (s == ";" and i in [4, 18, 20]): #insert your desire list s = ":" result = result + s print(result)