split string in to 2 based on last occurrence of a separator
Use rpartition(s)
. It does exactly that.
You can also use rsplit(s, 1)
.
>>> "a b c,d,e,f".rsplit(',',1)
['a b c,d,e', 'f']
You can split a string by the last occurrence of a separator with rsplit
:
Returns a list of the words in the string, separated by the delimiter string (starting from right).
To split by the last comma:
>>> "a b c,d,e,f".rsplit(',', 1)
['a b c,d,e', 'f']