i am tying to solve the following question on a competitive coding website where i have to convert '->' to '.' only in the code section but not in the comments. https://www.hackerearth.com/problem/algorithm/compiler-version-2/
i have tried to write a solution but everytime i run it it gives me IndexError message. Some help is much appreciated. Below is my solution
import copy
temp_list = []
while True:
string = input()
if string != "":
temp_list.append(string)
string = None
else:
break
for i in range(len(temp_list)):
j = 0
while j <= (len(temp_list[i]) - 2):
if string[i][j] == '-' and string[i][j + 1] == '>':
#print("Hello WOrld")
temp_string = string[i][:j] + '.' + string[i][j + 2:]
string[i] = copy.deepcopy(temp_string)
elif string[i][j] == '/' and string[i][j + 1] == '/':
#print("Break")
break
else:
#print(j)
j += 1
for i in temp_list:
print(i)