3 ms·
But of course doing it the way you described is subtly unintuitive because it leads to either (1) duplication of the default value (or the need to pass it aroun
by tedmiston 5y ago
But of course doing it the way you described is subtly unintuitive because it leads to either (1) duplication of the default value (or the need to pass it around as a constant to every access point) and (2) does not work anywhere the dict is accessed directly like:
d['foo']
whereas defaultdict handles the default value for you correctly independently of the access method.
IMO defaultdict is ideal for this use case.