[Python-ideas] Star assignment in iterator way?

Serhiy Storchaka storchaka at gmail.com
Tue Nov 21 04:54:25 EST 2017


21.11.17 11:27, Kirill Balunov пише:
>     Your implementation iterates seq multiple times. But iterable
>     unpacking syntax works with an arbitrary iterable, and iterates it
>     only once.
> 
> 
> Oh sorry, I know that my implementation iterates seq multiple times, I 
> only provide this to show the idea. It can be much optimized at C level. 
> I just want to understand if it's worth the time and effort.

You can implement the first case, but for other cases you will need a 
storage for saving intermediate items. And using a list is a good option.

>     And you already have mentioned a question about mutable sequence.
> 
>     If these conditions and restrictions suit you, you can use your
>     good_star_exp() in your code or share it with others. But the
>     semantic of iterable unpacking can't be changed.
> 
> 
> And how do you look at something like this (deferred star evaluation)?:
> 
> a, ?*b, c, d = something_iterable

This will be not different from

a, *b, c, d = something_iterable
b = iter(b)

There is nothing deferred here.

The only possible benefit can be in the case

a, b, ?*c = something_iterable

But I have doubts that this special case deserves introducing a new syntax.



More information about the Python-ideas mailing list