There is a Python dictionary function that will do this whole if statement in one line: setdefault().