[Python-ideas] Use the plus operator to concatenate iterators

random832 at fastmail.us random832 at fastmail.us
Wed Aug 5 04:37:00 CEST 2015


On Tue, Aug 4, 2015, at 21:34, Chris Angelico wrote:
> Almost completely useless. Multiplying an *iterable* by an integer
> will often be useful (eg multiplying list by int), but multiplying an
> *iterator* (or even just adding one to itself) is going to be useless,
> because the first time through it will exhaust it, and any
> well-behaved iterator will remain exhausted once it's ever raised
> StopIteration. (Note that the 'class iter' that I posted earlier is
> NOT well-behaved. You can add something onto an exhausted iterator and
> rejuvenate it. It'd take a couple extra lines of code to fix that.)

Suppose iterator * number returns a new iterator which will iterate
through the original iterator once, caching the results, and then yield
the cached results n-1 times.


More information about the Python-ideas mailing list