Steven D'Aprano: > > s = "aaabbbbbaabbbbbb" > > from itertools import groupby > > print [(h,leniter(g)) for h,g in groupby(s)] > > s isn't an iterator. It's a sequence, a string, and an iterable, but not > an iterator.
If you look better you can see that I use the leniter() on g, not on s. g is the iterator I need to compute the len of. > I hope you know what sequences and strings are :-) Well, I know little still about the C implementation of CPython iterators :-) But I agree with the successive things you say, iterators may be very general things, and there are too many drawbacks/dangers, so it's better to keep leniter() as a function separated from len(), with specialized use. Bye and thank you, bearophile -- http://mail.python.org/mailman/listinfo/python-list