3 ms·
Not really; where would you put it inside the []?
by int_19h 4y ago
Not really; where would you put it inside the []?
- dragonwriter 4y agoIn the example from the end of the earlier post: y for x in xs if (y:=x.ComputeSomething()).IsFoo and y.IsBar
- int_19h 4y agoI suppose that works, although readability is not great, to put it mildly.
- texaslonghorn5 4y agoMuch better would be [(y:=x.ComputeSomething()) for x in xs if y.IsFoo and y.IsBar]
- int_19h 4y agoThat doesn't work, because that first subexpression is evaluated last, after "if".
- ChadNauseam 4y agoFor another example of how to use the walrus operator, I use it multiple times in the code I linked a few comments up