Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to strip characters from the right side of every word in Python?

Say, if I have a text like

text='a!a b! c!!!'

I want an outcome like this:

text='a!a b c'

So, if the end of each words is '!', I want to get rid of it. If there are multiple '!' in the end of a word, all of them will be eliminated.

like image 364
Naoko Nishimura Avatar asked Apr 16 '13 22:04

Naoko Nishimura


1 Answers

print " ".join(word.rstrip("!") for word in text.split())
like image 109
Joran Beasley Avatar answered Oct 06 '22 15:10

Joran Beasley