# Write a function that takes a string and a substring and # removes the second instance of the substring from the string # without using any built-in functions/methods besides len() # (i.e. you may NOT use .index()). # The substring will be at most three characters long. # # After completing the solution without using built-in functions/methods, # rewrite a function to use built-in functions/methods. # Then, compare both solutions. def removeSecond(l, n): string = l substring = n count = 0 for i in range(0, len(string)): if string[i:(i + len(substring))] == substring: count += 1 if count == 2 : string = string[0:i] + string[i + len(substring): ] #break # how else can we break the loop return string print(removeSecond('bird', 'i')) # bird print(removeSecond('bird', 'x')) # bird print(removeSecond('ibiridi', 'i')) # ibridi print(removeSecond('kiaeb', 'iae')) # kiaeb print(removeSecond('kiaebiaeriaediae', 'iae')) # kiaebriaediae print(removeSecond('kiaebiariaediaeia', 'iae')) # kiaebiardiaeia