def getkey(mapping, value, default=None, use_id=False):
    '''Returns the first key mapping to value, as encountered via iteritems(), otherwise default.  Obviously, works best for injective maps.
    '''
    if use_id:
        for key, val in mapping.items():
            if val is value:
                return key
    else:
        for key, val in mapping.items():
            if val == value:
                return key
    return default
def getkey ( mapping , value , default = None , use_id = False ) : if use_id : for key , val in mapping . items ( ) : if val is value : return key else : for key , val in mapping . items ( ) : if val == value : return key return default
Returns the first key mapping to value, as encountered via iteritems(), otherwise default.  Obviously, works best for injective maps.