How to remove characters from a string?

3

The program should read two strings and remove from the first string all the letters that occur in the second string. Example: Let the strings be "chocolate" and "hollow", so the program should print "hlte". How to solve the problem using string knowledge? Pseudocode:

 string1 = raw_input()
 string2 = raw_input()
 stringresultante = caracteres da string1 - caracteres da string2
 print stringresultante
    
asked by anonymous 28.03.2016 / 20:42

1 answer

6

Since you are going to remove a specific character from a String using another String , you will need to loop to String that has the characters "hollow" to check on your second String "chocolate".

See the example below.

>>>
>>> a = "a!b@c#d$"
>>> b = "!@#$"
>>> for i in range(0,len(b)):
...  a =a.replace(b[i],"")
...
>>> print a
abcd
>>>
    
28.03.2016 / 21:35