Aug-04-2023, 06:44 AM
Can't see a one-liner to do this.
# add a unwanted character at the end of the string or you won't get the last wanted characters mystring = 'ab|cd!ef|gh!ij|kl!mn|' # define what you want to keep wanted = 'abcdefghijklmnopqrstuvwxyz' count = 0 for i in range(len(mystring)): if not mystring[i] in wanted: seq = mystring[count:i] print(seq) count = i+1