Victor Stinner wrote:
I prefer str.join() approach: write a single chunks() function which
takes a sequence, instead of modifying all sequence types around the
world ;-)

Even if a general sequence-chunking function is thought useful,
it might be worth providing a special-purpose one as a string
method in the interests of efficiency. Splitting a string into
a sequence of characters, messing with it and then joining it
back into a string is a pretty expensive way to do things.

While most uses would probably be for short strings, I can
think of uses cases involving large ones. For example, to
format a hex dump into lines with 8 bytes per line and spaces
between the lines:

   data.group(2, ' ').group(24, '\n')

And even for short strings, processing lots of them in a loop
could get expensive with the general-purpose approach.

--
Greg

_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to