Hey guys, I was building a programme for my school computer exercise which involved me to replace the first and last word of a string. Now I've done it using my own indigenous ways but I'm rather interested to learn the most efficient way I could do it using Python
a = "this is the demo sentence."
I'd like the result of my python function to be:
b = "This is the demo Sentence."
The tricky part of it is that there might be spaces on the front or the end of the string. I need those to be preserved.
Here's what I mean:
a = " this is a demonstration sentence. "
The result would need to be:
b = " This is a demonstration Sentence. "
I'm also interested in opinions on whether a regex would do this job better than python's inbuilt methods, or vice versa.