For consistency:
if 'prevValue' in res.keys()

Unless there is some other value to using .keys() here that I'm missing.