You can check for a key in a dict with "if k in d:", you don't need "if k in d.keys():"