Given a dictionary like so:
my_map = {\'a\': 1, \'b\': 2}
How can one invert this map to get:
inv_map = {1: \'a\', 2: \'b\'
To do this while preserving the type of your mapping (assuming that it is a dict or a dict subclass):
dict
def inverse_mapping(f): return f.__class__(map(reversed, f.items()))