[issue34508] return of non-parenthesized star-unpacking expression a SyntaxError

Serhiy Storchaka report at bugs.python.org
Tue Aug 28 12:42:08 EDT 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

> It would need a special case so that `for x in *a, *b:` doesn't first construct a tuple of all elements in a and b. Thoughts?

It may be surprising that `for x in *a, *b:` behave differently from `for x in (*a, *b):`.

It is idiomatic to create a list of keys and iterate it if you want to modify the dict during iterating:

    for key in list(d):
        # modify d

This can be written in a form

    for key in [*d]:
        # modify d

or

    for key in (*d,):
        # modify d

(although the latter variant is slightly slower).

----------

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


More information about the Python-bugs-list mailing list