maegul on Nostr: I never paid attention to the walrus operator argument in #python nor have I used it ...
I never paid attention to the walrus operator argument in #python nor have I used it much.
But just now, using a walrus operator in a list comprehension with a conditional made me realise that it may have marked the point at which python was no longer a beginner friendly lang.
That the walrus operator has to be used in the conditional and not the expression feels wrong to me but is also "technically correct"(?)
valid:
[r for n in x if (r:=f(n)) < 10]
invalid:
[(r:=f(n)) for n in x if r < 10]
But just now, using a walrus operator in a list comprehension with a conditional made me realise that it may have marked the point at which python was no longer a beginner friendly lang.
That the walrus operator has to be used in the conditional and not the expression feels wrong to me but is also "technically correct"(?)
valid:
[r for n in x if (r:=f(n)) < 10]
invalid:
[(r:=f(n)) for n in x if r < 10]