So I have a long list of strings in the same format, and I want to find the last "." character in each one, and replace it with ". - ". I've tried using rfind, but I can't seem to utilize it properly to do this.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I would use a regex:
To replace from the right:
In use:
You can use the function below which replaces the first occurrence of the word from right.
A one liner would be :
str=str[::-1].replace(".",".-",1)[::-1]
Naïve approach:
Aditya Sihag's answer with a single
rfind
:This should do it