packing unpacking depends on order.

Sven R. Kunze srkunze at mail.de
Wed Sep 2 13:26:49 EDT 2015


I agree as well. First evaluate the right side, then assign it to the 
left side at once.

On 02.09.2015 12:22, Nick Sarbicki wrote:
> That's interesting. I agree with you, I'd prefer the second result in 
> both cases.
>
> But makes sense as it evaluates left to right and seems to break up 
> the unpacking into separate statements.
>
> Could be useful if you want to hold the results of a generator in 
> sequence, can call the same function multiple times and unpack as above.
>
> On Wed, Sep 2, 2015 at 11:07 AM Antoon Pardon 
> <antoon.pardon at rece.vub.ac.be <mailto:antoon.pardon at rece.vub.ac.be>> 
> wrote:
>
>
>     >>> a = [1, 2, 3, 4, 5]
>     >>> b = 1
>     >>> b, a[b] = a[b], b
>     >>> a
>     [1, 2, 1, 4, 5]
>     >>> a = [1, 2, 3, 4, 5]
>     >>> b = 1
>     >>> a[b], b = b, a[b]
>     >>> a
>     [1, 1, 3, 4, 5]
>
>     I think I understand how it gets these results
>     but I'm not really happy with them. I think python
>     should give the second result in both cases.
>
>     --
>     Antoon Pardon
>
>     --
>     https://mail.python.org/mailman/listinfo/python-list
>
> -- 
>  - Nick
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150902/cdfd4444/attachment.html>


More information about the Python-list mailing list