Mark Dickinson <dicki...@gmail.com> 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=3))
[('1', '2', '345'), ('1', '23', '45'), ('1', '234', '5'), ('12', '3', '45'), 
('12', '34', '5'), ('123', '4', '5')]

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39045>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to