Given a string: s = FFFFRRFFFFFFFPPRRRRRRLLRLLRLLLPPFPPLPPLPPLFPPFFPFLRPFFRRLLRPFPRFFFFFFFLFDRRFRRFFFFFFFFRQEE
The delimiting characters are P
, Q
, D
and E
I want to be able to split the string on these characters.
Based on: Is it possible to split a string on multiple delimiters in order?
I have the following
def splits(s,seps):
l,_,r = s.partition(seps[0])
if len(seps) == 1:
return [l,r]
return [l] + splits(r,seps[1:])
seps = ['P', 'D', 'Q', 'E']
sequences = splits(s, seps)
This gives me:
['FFFFRRFFFFFFF',
'PRRRRRRLLRLLRLLLPPFPPLPPLPPLFPPFFPFLRPFFRRLLRPFPRFFFFFFFLF',
'RRFRRFFFFFFFFR',
'',
'E']
As we can see the second entry has many P
.
I want is the occurrence of characters between the last set of P
, not the first occurrence (i.e., RFFFFFFFLF
).
Also, the order of occurrence of the delimiting characters is not fixed.
Looking for solutions/hints on how to achieve this?
Update: Desired output, all set of strings between these delimiters (similar to the one shown) but adhering to the condition of the last occurrence as above
Update2: Expected output
['FFFFRRFFFFFFF',
'RFFFFFFFLF', # << this is where the output differs
'RRFRRFFFFFFFFR',
'',
''] # << the last E is 2 consecutive E with no other letters, hence should be empty