[Python-ideas] + operator on generators

Koos Zevenhoven k7hoven at gmail.com
Fri Jun 30 14:02:45 EDT 2017


On Jun 30, 2017 2:23 PM, "Erik Bray" <erik.m.bray at gmail.com> wrote:

I actually really like this proposal, in additional to the original
proposal of using '+' to chain generators--I don't think it
necessarily needs to be extended to *all* iterables.  But this
proposal goes one better.  I just have to wonder what kind of strange
unexpected bugs would result.  For example now you could add a list to
a string:

    >>> list(['a', 'b', 'c'] + 'def')
    ['a', 'b', 'c', 'd', 'e', 'f']

Personally, I really like this and find it natural.  But it will break
anything expecting this to be a TypeError.


Note that you can already do:

[*iterable1, *iterable2]

Or like in your example:

>>> [*['a', 'b', 'c'], *'def']
['a', 'b', 'c', 'd', 'e', 'f']

At least I think you can do that in 3.6 ;)

-- Koos (mobile)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170630/fffc41e1/attachment.html>


More information about the Python-ideas mailing list