[Python-ideas] + operator on generators

Serhiy Storchaka storchaka at gmail.com
Mon Jun 26 09:53:15 EDT 2017


26.06.17 13:47, Joao S. O. Bueno пише:
> On 25 June 2017 at 20:55, Danilo J. S. Bellini <danilo.bellini at gmail.com 
> <mailto:danilo.bellini at gmail.com>> wrote:
> 
>     On Sun, Jun 25, 2017 at 3:06 PM, lucas via Python-ideas
>     <python-ideas at python.org
>     <mailto:python-ideas at python.org>>wrote:
> 
>         I often use generators, and itertools.chain on them.
>         What about providing something like the following:
> 
>              a = (n for n in range(2))
>              b = (n for n in range(2, 4))
>              tuple(a + b)  # -> 0 1 2 3
> 
> 
> You know you can do `tuple(*a, *b)` , right?
> 
> The problem with the "*" notation is that it will actually render the 
> iterable
> contents eagerly - unlike something that would just chain them.
> But for creating tuples, it just works.

Even the tuple constructor is not needed.

 >>> *a, *b
(0, 1, 2, 3)



More information about the Python-ideas mailing list