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

Chris Angelico rosuav at gmail.com
Wed Aug 5 03:34:56 CEST 2015


On Wed, Aug 5, 2015 at 11:32 AM, Joonas Liik <liik.joonas at gmail.com> wrote:
> no opinion if its a good idea or not, however, if iterator + iterator...
>
> iterator * number

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.)

ChrisA


More information about the Python-ideas mailing list