3 ms·
from collections import defaultdict d = defaultdict(int) d['non_existant_key']
by basdftrewq 6y ago
from collections import defaultdict
d = defaultdict(int)
d['non_existant_key']
- st0le 6y agoNot quite the same what OP asked for. This will create the key and assign value 0 to it.