Python String rsplit() Method
Splits the string by the given separator, from right to left. An array is returned for the separated strings. And optional number of occurrences can be specified.
string.rsplit(separator = " ", max_strings = -1)
||Optional. The string by which to split the given string. The default is a space (" ")|
||Optional. The maximum number of strings to return. The default is -1 which means "all strings that resulted from the split operation".|
str = 'You say tomato, I say tomato, the French say tomate.' print(str.rsplit('tomato')) print(str.rsplit('tomato', 1))
['You say ', ', I say ', ', the French say tomate.'] ['You say tomato, I say ', ', the French say tomate.']
If you specify max_strings then the number of items that will be returned is max_strings+1.