Hacker News new | past | comments | ask | show | jobs | submit login

This is due to PEP 448 "Additional Unpacking Generalisations" [1], which was approved with effect from Python 3.5. Other examples:

    x, y, *r, z = range(7)
    print("x: {}, y: {}, r: {}, z: {}".format(x, y, r, z))
    # prints: x: 0, y: 1, r: [2, 3, 4, 5], z: 6
     
    x, (qa, *qr), *r = [1, [2, 3, 4], 5, 6]
    print("x: {}, qa: {}, qr: {}, r: {}".format(x, qa, qr, r))
    # prints: x: 1, qa: 2, qr: [3, 4], r: [5, 6]
The same PEP allows expanding lists and dictionaries in literals:

    r = [*r1, *r2]    # Same as r = r1 + r2 if they are lists
    d = {**d1, **d2}  # Merges d1 and d2 into d
[1] https://www.python.org/dev/peps/pep-0448/



I was mistaken, sorry. Those unpackings work as of Python 3.0 due to PEP 3132 "Extended Iterable Unpacking" [2]. PEP 448 is just for those examples in the second half of my comment.

[2] https://www.python.org/dev/peps/pep-3132/




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: