2 ms·
One horribly fragile solution to this depends on global name resolution: d = defaultdict(lambda: len(d)) However, it's probably better to avoid defaultdict
by klyrs 6y ago
One horribly fragile solution to this depends on global name resolution:
d = defaultdict(lambda: len(d))
However, it's probably better to avoid defaultdict altogether and implement __missing__ in a subclass of dict.