Python Practice › String Programs › Program 67

Split on the last delimiter

EasyString Programs · 67 of 106

Write a Python program to split a string on the last occurrence of a delimiter.

Advertisement
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

  1. rsplit(",", 1) splits once, from the right.

Solution

Python
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']
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs