One-line expression to map dictionary to another
- by No Such IP
I have dictionary like
d = {'user_id':1, 'user':'user1', 'group_id':3, 'group_name':'ordinary users'}
and "mapping" dictionary like:
m = {'user_id':'uid', 'group_id':'gid', 'group_name':'group'}
All i want to "replace" keys in first dictionary with keys from second (e.g. replace 'user_id' with 'uid', etc.)
I know that keys are immutable and i know how to do it with 'if/else' statement.
But maybe there is way to do it in one line expression?