Say I have the following string
s = "DH3580-Fr1-TRG-TRB-DH1234-Fr3"
and I have a list of characters
l = ['Fr1', 'TRG', 'TRB', 'SOUL']
Excluding the string upstream of the first -
(DH3580
), I want to scan s
until it finds the last element which is present in l
, in this case TRB
. Finally I want to split the string s
by the immediate -
thereafter. So that s
becomes the list
['DH3580-Fr1-TRG-TRB', 'DH1234-Fr3']
What would be the best way to do this in python3?
There is a very similar question here, although for JavaScript