New assignmens ...

Peter J. Holzer hjp-python at hjp.at
Wed Oct 27 05:34:56 EDT 2021


On 2021-10-27 19:05:52 +1100, Chris Angelico wrote:
> On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon <antoon.pardon at vub.be> wrote:
> > while (a, b) := next_couple(a,b)[-1]:
> >      ...
[...]

> I'm not sure that it's much of a use-case; isn't it an infinite loop as written?
> 
> And that's the problem. With multiple-assignment, the overall value is
> going to be the tuple, so you then have to add extra parentheses and
> subscripting to get what you want to check.

Right. I think for that you would want something like what Go does in
if:

    if [assignment-statement ;] condition {
        statements
    }

Then you could write

    while a, b = next_couple(a,b); b:
        ...

That doesn't even need the walrus operator.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20211027/7d2f8ca3/attachment.sig>


More information about the Python-list mailing list