3 ms·
meanwhile python be out here like: [(m.group(1), len(m.group())) for m in re.finditer(r"([a-z])\1*", “aaaabbbcca")
by riwsky 6y ago
meanwhile python be out here like:
[(m.group(1), len(m.group()))
for m in re.finditer(r"([a-z])\1*", “aaaabbbcca")
- eesmith 6y agoimport itertools [(c, len(list(it))) for (c, it) in itertools.groupby("aaaabbbcca")] It's not the first time I've wanted def ilen(it): return sum(1 for _ in it) as part of itertools. Which would make the second line be: [(c, itertools.ilen(it)) for (c, it) in itertools.groupby("aaaabbbcca")] Rejected many times, eg, from 2010: https://bugs.python.org/issue9547 https://bugs.python.org/issue9547 .