No terse strtok() in Python
Submitted by Dan Muresan on
It turns out in Python there's no generator version of str.split()
(which produces a list of substrings). Some recipes in this Stackoverflow answer, of which I suppose
def split_iter(string):
return (x.group(0) for x in re.finditer(r"[A-Za-z']+", string))
is "terse enough" (and much more functional, though it requires proper escaping of re
-special characters). It's hard not to quip that C has had strtok
(or, more reasonably, strtok_r
) for a very long time.