Issue
So let’s say I have a string, like this:
string = '12345+67890'
I want to go back to search for that plus, and add a letter ‘H’, so the end result would be like this:
string = '12345+h67890
Also, what if I want to get the latest +, so if there is two +’s, I want to get the last +?
Any help would be appreciated!
Solution
You could use reverse split to split on the last instance of +, then join with +H:
>>> '+H'.join('123+456+789'.rsplit('+',1))
'123+456+H789'
Answered By – Mark Tolonen
Answer Checked By – Dawn Plyler (BugsFixing Volunteer)