News for hackers. Stuff that matters.
Re:Python 3.11: “Zero cost” exception handling by dec0dedab0de on Wednesday October 06, 2021 @11:08AM (#28774048)
If I find if's and try's looking ugly for a particular use case I try to figure out how to get rid of them. For your first example I would do this, assuming value is a number.

  value += dict_.get('key',0)
Though I agree with using an if in the second example, if there isn't a better way to do the iteration to avoid looking up keys that don't exist.

There are no comments on this comment yet.