You're flipping the keys and values in the dict. Is there a reason for not building it this way from the first place?