I am looking for the most pythonic way to replace the first and last word of a string (doing this based on letters will not work for various reasons). To demonstrate what I'm trying to do, here is an example.
a = "this is the demonstration sentence."
I would like the result of my python function to be:
b = "This is the demonstration Sentence."
Its hard part is that there may be spaces at the front or end of the line. I need those that need to be saved.
Here is what I mean:
a = " this is a demonstration sentence. "
The result should be:
b = " This is a demonstration Sentence. "
He would also be interested in opinions about whether a regular expression would do this job better than python-based built-in methods, or vice versa.
source share