如何从Python中每个单词的右侧删除字符?

Nao*_*ura 6 python strip python-2.7

说,如果我有像这样的文字

text='a!a b! c!!!'
Run Code Online (Sandbox Code Playgroud)

我想要一个这样的结果:

text='a!a b c'
Run Code Online (Sandbox Code Playgroud)

所以,如果每个单词的结尾都是'!',我想摆脱它.如果有多个'!' 最后,所有这些都将被淘汰.

Jor*_*ley 8

print " ".join(word.rstrip("!") for word in text.split())
Run Code Online (Sandbox Code Playgroud)