Python: Invert a mapping
Given this dictionary:
my_map = { 'a': 1, 'b':2 }
you can invert it:
inv_map = {v: k for k, v in my_map.items()}
to get:
$ inv_map
{ 1: 'a', 2: 'b' }
Via StackOverflow.com.
Given this dictionary:
my_map = { 'a': 1, 'b':2 }
you can invert it:
inv_map = {v: k for k, v in my_map.items()}
to get:
$ inv_map
{ 1: 'a', 2: 'b' }
Via StackOverflow.com.
Leave a comment