5 ms·
I think this defaultdict solution is the best, or at least most pythonic. I really thought if this was possible to do in a single dictionary comprehension, wit
by YurgenJurgensen 5y ago
I think this defaultdict solution is the best, or at least most pythonic.
I really thought if this was possible to do in a single dictionary comprehension, with some kind of d = {k: sum(v) for k, v in <something>}, but whatever goes in <something> ends up being super ugly.
- runekaagaard 5y agoWhat you do mean ugly :) [{"thing": k, "count": v} for k, v in [[c, c.update({x["thing"]: x["count"]})] for c in [Counter()] for x in response][0][0].items()]