Jonathan Slenders writes: > Good catch! One correction here, I somewhat mixed up the benchmarks. I > forgot both projects of mine required support for universal line endings > exactly like splitlines() does this out of the box.
I can't remember ever seeing an application where such a method is not only useful but needs to be extremely efficient, so I'm a little suspicious of the generality of the need. On the other hand, for this particular case you should be able to just subtract the string allocations from .splitlines. How about generalizing it into a maplines method, whose basic internal function is to generate an iterator over (line_start, line_end) pairs (line_end is useful because the separator is not necessarily a single character). Then it could optionally take a function to map over those, as well as an optional separator string. I suppose it would usually be a single character, except for universal newlines, which would be the default case both because it's so common and because it's not a constant string. This would then be the implementation of splitlines, as well as a mapping tool for records (usually lines, but could be paragraphs) in a 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/R5DI64RFOJYQ57NHNMBKC3RPHZJ2KRPV/ Code of Conduct: http://python.org/psf/codeofconduct/