4 ms·
Don't wait for 3.8, and don't bother with defaultdict. collections.Counter is what you want for the counting case. dict.get() + dict.setdefault() for the gene
by sametmax 8y ago
Don't wait for 3.8, and don't bother with defaultdict.
collections.Counter is what you want for the counting case.
dict.get() + dict.setdefault() for the general case.
defaultdict is only useful if the factory is expensive to call.