you can probably create `partitions` using `defaultdict` and avoid this test here