Reputation: 247
I am trying to do multiple replaces in python but the replace is not working, it only replaces the <UNK>
but not </s>
.
Can anybody tell me where the error is?
text=text.replace(":<UNK>","")
text=text.replace("</s>","")
Upvotes: 0
Views: 572
Reputation: 1052
Your code worked correctly but You can use regular expression to find and replace the text.
import re
text = '1.595879e-04(Kan) 7.098440e-08(Şekerini:<UNK>) 2.558586e-06(Etkileyen) 7.671361e-07(Besinler) 3.731427e-02(</s>) (ailehekimligi-0000000001)'
output = re.sub(r':<UNK>', '', text)
output = re.sub(r':</s>', '', text)
print(output)
also if you have unicode string, you can use u''
before text and your replace statement.
Upvotes: 2