[issue36761] Extended slice assignment + iterable unpacking

wim glenn report at bugs.python.org
Mon May 13 17:33:08 EDT 2019


wim glenn <wim.glenn at gmail.com> added the comment:

Serhiy,

`a, *L[::2] = "abc"` as an alternative is interesting, thanks.  The other example `L[:], *rest = 'abcdef'` is less interesting because L[:] can be arbitrary size.

When noticing this, I had tried to consume a generator into every other position in a list by using:

    L[::2], *extra = g

Though there are obvious workarounds (e.g. using `itertools.islice`), it surprised me that CPython did not "do what I mean" out of the box. 

However, since creating the issue, it was brought to my attention that trying to handle this assignment may result in potential ambiguity, for example:

    L = [0, 1, 2]
    L[::2], *rest = "ab", "c", "d"

There is no obvious choice for result here. So, perhaps this issue should just be closed.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36761>
_______________________________________


More information about the Python-bugs-list mailing list