Apologies for the bad formatting. Here are the relevant bits, better formatted
(I hope):
>>> segment = lambda s, m: (tuple(s[i:j] for i, j in zip((0,)+c,
c+(len(s),)))
... for c in itertools.combinations(range(1, len(s)), m-1))
>>>
>>> list(segment("12345", m=3))
[('1', '2', '345'), ('1', '23', '45'), ('1', '234', '5'), ('12', '3',
'45'), ('12', '34', '5'), ('123', '4', '5')]
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/LLJJIWRGC726Y4OSGIETP3SE55PIQOYT/
Code of Conduct: http://python.org/psf/codeofconduct/