Python Practice › String Programs › Program 67
Split on the last delimiter
Write a Python program to split a string on the last occurrence of a delimiter.
Input
"l,e,a,r,n,I,n,g,p,y,t,h,o,n"
Output
['l,e,a,r,n,I,n,g,p,y,t,h,o', 'n']
Approach
rsplit(",", 1)splits once, from the right.
Solution
text = "l,e,a,r,n,I,n,g,p,y,t,h,o,n"print(text.rsplit(",", 1))Output
['l,e,a,r,n,I,n,g,p,y,t,h,o', 'n']
Learn the concept
New to this topic? Read the lesson, then come back.