On Sat, Dec 14, 2019, at 04:06, smfiles  wrote:
> 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. With segment(), you can avoid tedious calculation and 
> indexing if you want to segment a string.
> 
> For example:
> 
> segment('1234', m=3) -> [('1', '2', '34'), ('1', '23', '4'), ('12', 
> '3', '4')]
> segment('12345', m=3) -> [('1', '2', '345'), ('1', '23', '45'), ('1', 
> '234', '5'), ('12', '3', '45'), ('12', '34', '5'), ('123', '4', '5')]

This is trivial to do with itertools.combinations - just take all combinations 
of 2 [m-1] values between 1 and 4 [len(s)-1], and use those as places to cut 
the string.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/U2AGKBADRVMYUQA3G6Z2TAWAX6E2XS3X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to