Effectively replace a key in a dictionary

sorry, bug