Maybe you could use [collections.defaultdict](https://docs.python.org/3.3/library/collections.html#collections.defaultdict)