Consider changing back to an ordinary dict. It is a very cheap operation without recomputing hash values. The only slow part is the interpreter needs to update all references.
Also, for whatever reason, lookup in dict() works a little faster than in defaultdict.
Software Development, Programming languages comparison, database benchmarks, programming books and other technical topics. Feedback: contact@nickshpil.com...