On 2026-06-15, Paul Rubin <[email protected]> wrote:
> Jon Ribbens <[email protected]> writes:
>>>  { a : int(b)) for x in xs if (a,b := x.split()) }
>> No, for three reasons. Firstly, the lines with units result in x.split()
>> having 3 members, so you can't assign it to a 2-tuple.
>
> Oh yes I had intended to say x.split()[:2] but somehow left that out.
>
>> Secondly, it appears that (a, b := x) means "create a tuple whose
>> first member is a and whose second member is x, and also assign x to
>> b", which is not at all what we need.
>
> Yuck, I had expected tuple unpacking.  Sounds like a pitfall comparable
> to "=" vs "==" that kept the := operator out of the language for so
> long.  Oh well.

My biggest complaint about := is the arbitrary and mysterious
restrictions on what you can use on the left hand side. You can't
even say "a.b := c". The PEP that introduced ":=" barely even
mentions these restrictions, let alone discusses or explains them.
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to