Dec-15-2020, 09:45 AM
This could be done using split, construct and join.
- split string at delimiter
- construct stream of substrings with putting delimiter back
- join substrings using repalcement string
There are corner cases which must be tested/addressed but something along those lines is sufficient to start:
- split string at delimiter
- construct stream of substrings with putting delimiter back
- join substrings using repalcement string
There are corner cases which must be tested/addressed but something along those lines is sufficient to start:
def formatter(text, delimiter='.', replacement='\n'): stream = (f'{token.strip()}{delimiter}' for token in text.split(delimiter) if token) return replacement.join(stream) s = 'I want to be a developer. I also want to learn AWS. I am going to practice joining strings.' print(formatter(s)) -> I want to be a developer. I also want to learn AWS. I am going to practice joining strings.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.