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

I would be fascinated to hear how you would do the following in one line of idiomatic C using commas.

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

The major objective appears to be avoiding duplicating work unnecessarily when doing multiple things in a single expression. The previous way of doing the above would have been:

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

I can think of multiple instances in which I could have used this feature in cases similar to the above.

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