In the first instance, the original code is readable and tells me exactly what's what. In your example, you're sacrificing readability for being clever.
Clear code(even if verbose) is better than being clever.
In the first instance, the original code is readable and tells me exactly what's what. In your example, you're sacrificing readability for being clever.
Clear code(even if verbose) is better than being clever.
defaultdict is ubiquitous in modern python, and is far from a complicated concept to grasp.
The difference between the examples is so trivial I'm not really sure why the parent comment felt compelled to complain.
Once you get used to a language's "quirks" (so long as they're considered idiomatic), they no longer feel quirky, and it's usually pretty quick.
I've definitely written some things that I came back to much later and had to relearn (which is somewhere between embarrassing and humbling).
That said, I'll change my mind here and agree on using std library, but I'd still have separate 'key' assignment here for more clarity.