def keymap(func, d, factory=dict):
 rv = factory()
 rv.update(zip(map(func, iterkeys(d)), itervalues(d)))
 return rv

def keymap ( func , d , factory = dict ) : rv = factory ( ) rv . update ( zip ( map ( func , iterkeys ( d ) ) , itervalues ( d ) ) ) return rv
apply function to keys of dictionary .