Q:

Full re-map of keys and values in a dictionary, set, list, etc?

I have a defaultdict(set) of various keys (sets), values (set of tuples), etc.
I also have a dictionary of various key (tuples), and values (strings).
For example maybe everything is in Japanese, with Japanese keys and values.
I have a mapping of Japanese -> English and want to update everything in my objects to the new key and values. The overall structure is the same, just the key/values are different named.
I can do this manually by looping over everything and popping/replacing but this is boring. I am curious if there is a more Pythonic way.

A:

Assuming you have a function named convert_keys or similar that you can pass in a Japanese key and get out the equivalent English key, as well as a convert_values function that does the same but with values, you might try something like this:
englishDict = dict(map(lambda x: (convert_keys(x[0]),convert_values(x[1])),japaneseDict.items()))

It's still essentially the same algorithm as popping/replacing but with map operating on each key/item pair you can condense it down to one line. 

