Does python have a build-in (meaning in the standard libraries) to do a split on strings that produces an iterator rather than a list? I have in mind working on very long strings and not needing to consume most of the string.
Not directly splitting strings as such, but the re module has re. finditer() (and corresponding finditer() method on any compiled regular expression). An example of how to use re. finditer() to iterate split strings would be helpful.
The splitlines() method splits a string into a list. The splitting is done at line breaks.
Not directly splitting strings as such, but the re
module has re.finditer()
(and corresponding finditer()
method on any compiled regular expression).
@Zero asked for an example:
>>> import re >>> s = "The quick brown\nfox" >>> for m in re.finditer('\S+', s): ... print(m.span(), m.group(0)) ... (0, 3) The (4, 9) quick (13, 18) brown (19, 22) fox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With