[issue42816] Add str.split_iter function
New submission from Martin Winks : Split string by given separator and return iterator as a result. The naive and not very efficient solution would be using current str.split: def split_iter(self: str, sep: str) -> 'Iterator[str]': return iter(self.split(sep)) Probably, need we'll some better solution without allocating new list. -- components: Unicode messages: 384270 nosy: ezio.melotti, uwinx, vstinner priority: normal severity: normal status: open title: Add str.split_iter function type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue42816> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17343] Add a version of str.split which returns an iterator
Martin Winks added the comment: > Perhaps the use case is already served by re.finditer() def split_whitespace_ascii(s: str): return (pt.group(0) for pt in re.finditer(r"[A-Za-z']+", s)) solution above does not cover all possible data and is incorrect for bytes-like objects. writing regular expressions for different separators/data would be a quite overheadish, so the idea of one-case solution doesn't seem to go very far and requires a bigger change in code for different separators. let's try to revive this one :) -- nosy: +uwinx ___ Python tracker <https://bugs.python.org/issue17343> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com