I recommend using ```collections.defaultdict``` here to avoid this block of code.