Reply to post: Re: Reinventing a more limited wheel

Python creator Guido van Rossum sys.exit()s as language overlord


Re: Reinventing a more limited wheel

The new syntax is not only using fewer characters, it's far clearer about what's actually going on than your example. Yes, you have to wrap your brain around the := operator, but that's just syntax and syntax is trivial. But when you compare your version:

[(x, y, x/y) for x, y in ((x, f(x)) for x in input_data) if y > 0]

vs. the PEP 572 version:

results = [(x, y, x/y) for x in input_data if (y := f(x)) > 0]

The fact that there will be a result for every item in the input_data list and that y = f(x) in the output are both made far clearer and more obvious in the latter form.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019