(May-26-2017, 03:07 PM)zivoni Wrote: is only slightly worse than
re.split('([{}]*)'.format(cs), 'Split this string and store splits')posted before that gives list instead of list of tuples.
Sorry, professor, but
split
does not give you "run" of the same separators - I believe OP asked to preserve each separator with its length(May-26-2017, 03:07 PM)zivoni Wrote: Neither one of them does what is wanted (split different separators while keeping "runs" of same separators) without some additional processsing.
list(itertools.chain(*re.findall(r'([^{0}]+)({0}*)'.format(cs), 'Split this string and store splits')))Mission accomplished. Yalla, next question?
Oh, and space was used just as an example
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.