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

Joseph Jevnik joejev at gmail.com
Wed Aug 5 03:02:52 CEST 2015


That would get _really_ messy with iterators that define an __add__,
sequence concat or number add function

On Tue, Aug 4, 2015 at 9:01 PM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

> On Tue, Aug 4, 2015 at 8:43 PM, Joseph Jevnik <joejev at gmail.com> wrote:
> > Iterators all all different types though. iter(list) returns a
> list_iterator
> > type, iter(dict.keys()) returns a dict_keys_iterator type and so on. Is
> your
> > suggestion that the standard lib types do this? How do we update all of
> the
> > existing iterators not in the stdlib that do not do this?
>
> In theory, this can be done inside PyNumber_Add(x, y).  It already
> checks for numbers or sequences and failing that can check for the
> __next__ method on its first operand and return  itertools.chain(x,
> y).
>
> > Finally, how is this better than itertools.chain?
>
> Shorter.  Especially when you chain more than two iterators.
>
> Nevertheless, I am -1 on the idea.  It is bad enough that Python
> abuses + as sequences concatenation operator.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150804/9269de78/attachment.html>


More information about the Python-ideas mailing list