Mark Dickinson added the comment:
For the record, this is an easy application of itertools.combinations:
>>> def segment(s, m):
... for c in itertools.combinations(range(1, len(s)), m-1):
... yield tuple(s[i:j] for i, j in zip((0,)+c, c+(len(s),)))
...
>>> list(segment("12345", m=
SilentGhost added the comment:
It is generally suggested to offer this sort of proposals for discussion on
python-ideas mailing list [0] first. There, you can elaborate on why you think
this is necessary, what sort of use cases this new method could have, etc. Once
there is a broad agreement
New submission from Lovi <1668151...@qq.com>:
I thought for a long time. I think it's necessary to add a segment method to
str type or string module. This method is used to split a string into m parts
and return all cases.
For example:
segment('1234', m=3) -> [('1', '2', '34'), ('1', '23', '