With regex:
You can do this with re.sub(). Match the required substring in the string and replace the substring with an empty string:
import re
text = ['hanks_NNS sir_VBP', 'Oh_UH thanks_NNS to_TO remember_VB']
curated_text = [re.sub(r'_\S*', r'', a) for a in text]
print curated_text
Conclusion:
['hanks sir', 'Oh thanks to remember']
Regex:
_\S* - Underscore followed by 0 or more non space characters
Without regex:
text = ['hanks_NNS sir_VBP', 'Oh_UH thanks_NNS to_TO remember_VB']
curated_text = []
for i in text:
d = []
for b in i.split():
c = b.split('_')[0]
d.append(c)
curated_text.append(' '.join(d))
print curated_text
Conclusion:
['hanks sir', 'Oh thanks to remember']
Problem with your code:
'_' , '_' .
for i in text:
k= i.split(" ")
print (k)
for z in k:
if "_" in z:
j=z.replace("_",'')
print (j)