On 12/14/19 4:06 AM, 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')] > > > I hope this proposal can be adopted.
My first impression is that if you aren't careful to use a string just slightly bigger then the number of segments, this could easily create a very large number of results. My guess is that the domain for using this is fairly restricted and an algorithm to do this isn't that hard to write and could easily be part of a module to handle that sort of thing. I also suspect different application domains may have differing 'rules' of what they want, for example, why do you assume no empty strings? Also, why just strings, maybe you want to do this to other sequences? -- Richard Damon _______________________________________________ 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/N3UPLXGXXV2PSFXK3VSFSS5H7HRMUAFM/ Code of Conduct: http://python.org/psf/codeofconduct/