I would write this block as
previous_value = persistent_values.get('previous_value')
persistent_values['previous_value'] = current_value
There is no if
needed as get()
returns None
when the key is not in the dict. And the second assignment is in both branches of the if.