I am very new to python and going through some course material and wrote this function to remove a specific character from string no matter how many times that character is in the string.
def remove_letter(): #Remove a selected letter from a string
base_string = str(raw_input("Enter String: "))
letter_remove = str(raw_input("Enter Letter: ")) #takes any size string
letter_remove = letter_remove[0]
string_length = len(base_string)
location = 0
while (location < string_length): #by reference (rather than by value)
if base_string[location] == letter_remove:
base_string = base_string[:location] + base_string[location+1::]
string_length -= 1
location+=1
print "Result: %s" % base_string
return
Now here is what i am not understanding, if i put "asdfasdfasdf" in the string and then choose to remove the letter "d" it works perfect. But if put "Hello" in the string and choose to remove the letter "l" it will only remove one "l" and the result will be "Helo". I can't understand why its working when i put "asdfasdfasdf" and now "Hello"