def dictreverse(mapping):
 return dict([(value, key) for (key, value) in mapping.iteritems()])

def dictreverse ( mapping ) : return dict ( [ ( value , key ) for ( key , value ) in mapping . iteritems ( ) ] )
takes a dictionary like {1:2 .