One-line expression to map dictionary to another

Posted by No Such IP on Stack Overflow See other posts from Stack Overflow or by No Such IP
Published on 2011-01-15T09:49:38Z Indexed on 2011/01/15 9:53 UTC
Read the original article Hit count: 188

Filed under:

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?

© Stack Overflow or respective owner

Related posts about python