I am currently debugging a function that returns a string that has a specific substring removed. I am not using any shortcuts (e.g. remove_all method); my aim is to keep the idea of this function and only fix the errors.
I have tried slicing the string by skipping the length of substring, but it does not fix the issue.
def remove_substring(string, substring):
p = string.find(substring)
# p is the next position in the string where the substring starts
lsub = len(substring)
while p >= 0:
string[p : len(string) - lsub] = string[p + lsub : len(string)]
p = string.find(substring)
return string
Whenever I run the function, it gives a TypeError: 'str' object does not support item assignment