News for hackers. Stuff that matters.
Re:PEP 572: Python assignment expressions has been accepted by antoinealb on Tuesday July 03, 2018 @06:26AM (#17449008)
As pointed, you can use either a default dict or just simply, and [more pythonic](https://blogs.msdn.microsoft.com/pythonengineering/2016/06/2...):

    try:
      bar[baz] += 1
    except KeyError:
      bar[baz] = 1
Also you can check if a key is in a dict simply by doing "if baz in bar" no need for "list(bar.keys())", which will be slow (temp object + linear scan) vs O(1) hashmap lookup.
Re:PEP 572: Python assignment expressions has been accepted by stfwn on Tuesday July 03, 2018 @06:48AM (#17449075)
The error-catching method seemed too drastic to me before, but the article explains the LBYL vs. EAFP arugument quite well. Thanks!

I should find a way to get more code reviews, I really enjoy learning these small nuggets of info.

Re:PEP 572: Python assignment expressions has been accepted by bocklund on Tuesday July 03, 2018 @07:57AM (#17449409)
Alternatively

`bar[baz] = bar.get(baz, 0) + 1`

One line and no error checking.

But the OP was probably just illustrating a basic example where you might have some more intense logic

Re:PEP 572: Python assignment expressions has been accepted by bb88 on Tuesday July 03, 2018 @07:08AM (#17449181)
It's also time saving since the hash lookup needs to be done at most 1, as well. GP has two lookups in the hash list.