I believe you could use collections.defaultdict here as well but this is actually maybe clearer.