The problem with "if 'due' in assessment:" is that due may be a valid key, set to none. .get() should cover if the key does not exist, and if it is None.