Fixing python 3 dictionary iteration