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...):
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.
[ Parent
| on HN ]
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.