If you reference elements string, you can use
str.rsplit()to separate each line by setting maxsplitto 1.
str.rsplit([sep[, maxsplit]])
Returns a list of words in a string, using sep as the delimiter string. If maxsplit is specified, the maximum maxsplit is executed, the rightmost ones. If sep is not specified or None, any line of spaces is a delimiter. Except for the separation on the right, rsplit () behaves like split (), which is described in detail below.
>>> lst = "YELLOW,SMALL,STRETCH,ADULT,T"
>>> lst.rsplit(',',1)[0]
'YELLOW,SMALL,STRETCH,ADULT'
>>>
source
share