classification
Title: PEP 3132 -- Extended Iterable Unpacking inconsistent assignment of * variable
Type: Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: mjaquier, steven.daprano
Priority: normal Keywords:

Created on 2019-10-18 12:11 by mjaquier, last changed 2019-10-18 12:41 by steven.daprano.

Messages (2)
msg354881 - (view) Author: Michael Jaquier (mjaquier) Date: 2019-10-18 12:11
x = [1,2,3]

Case (1)
*b, = x 
*b == [1, 2, 3]

Case(2)
*b, _ = x 
b = [1,2]



Is it not more logical for this to give consistent values regardless. 

i.e.,

*b, = [1,2,3] ; b == [1,2]

*b, _ = [1,3,2] ;  b == [1,2] ;  _ == [3]
msg354886 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-10-18 12:41
Why would they give the same result when the code is different?

    #1 assign c, d, e and everything left over goes into b
    *b, c, d, e, = [1, 2, 3, 4]

    #2 assign c, d and everything left over goes into b
    *b, c, d, = [1, 2, 3, 4]

    #3 assign c and everything left over goes into b
    *b, c, = [1, 2, 3, 4]

    #4 assign nothing and everything left over goes into b
    *b, = [1, 2, 3, 4]
History
Date User Action Args
2019-10-18 12:41:04steven.dapranosetnosy: + steven.daprano
messages: + msg354886
2019-10-18 12:11:14mjaquiercreate