Cast defaultdict to dict to avoid pickling the generator function