python - How do I implement rstrip for arbitrary strings? -


Say I have a bunch of strings, which either end in pineapple, ham May be , or grapes . What is the best way to prepare a list of "hidden stars", which is fine as the original stars, if only the pineapple is finished, then pineapple Will be trimmed by the end, and if the string ends with ham , then ham will be trimed?

For example, suppose that was my input

  ["I really like pineapple", "I do not like hem or grapes", "Today I ate "a lot of hams," but I eat many grapes "]   

then the output should be

  [" I really like " , "I do not like hem or grapes", "I ate a lot today", "but I ate too many grapes"]    

code> then . Simply join the end anchor at the end of your expression and make it only at the end. import re stuff = ["I really like pineapple", "I don" like hem or grapes "," I ate a lot today "," but I have so many grapes Eat "] [Re: ('' Pineapple Hamm) $ '', '', S) (in accessories for) [7]: ['I really like', 'I do not like hem or grapefruit' 'I have eaten a lot today', but I eat many grapes']

(I have left any additional strip To clean white space

re.sub ('{}} $' will do this with arbitrary list of stars to do this: Format ('.' .join (arbitrary_list_of_strings)), '', s) ...

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -