New assignmens ...

Antoon Pardon antoon.pardon at
Wed Oct 27 02:18:42 EDT 2021

Op 25/10/2021 om 18:47 schreef Christman, Roger Graydon:
> Message: 8
> Date: Mon, 25 Oct 2021 11:20:52 +0200
> From: Antoon Pardon <antoon.pardon at>
> To: python-list at
> Subject: Re: New assignmens ...
> Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db at>
> Content-Type: text/plain; charset=utf-8; format=flowed
> On 25/10/2021 11:20, Anton Pardon wrote:
>> Suppose I would like to write a loop as follows:
>   >    while ((a, b) := next_couple(a, b))[1]:
>   >        do needed calculations
>> What I can do is write it as follows:
>>      while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]:
>   >        do needed calculations
>> I really don't see what is gained by "forcing" me to right the second code over the first.
> No, nobody is forcing you to right it the second way over the first.
> Nobody is forcing you to use the walrus operator at all!
> Instead, I would recommend something more like:
>     while b:
>           do needed calculations
>           (a,b) = next_couple(a,b)

But AIU the walrus operator was introduced so we no longer needed, to write such code,
with the calculation of the next candidate at the bottom and the test at the top.
You just confirmed the walrus operator is not very useful once the next candidate is
no longer just a name.


More information about the Python-list mailing list