Answers for "function to switch dictionary keys and values"

0

swap keys and values in dictionary python

my_dict = {'x':1, 'y':2, 'z':3}
my_swapped_dict = {v: k for k, v in my_dict.items()}
#{1: 'x', 2: 'y', 3: 'z'}
Posted by: Guest on June-14-2021
0

switch case dictionary python

result = {
  'a': lambda x: x * 5,
  'b': lambda x: x + 7,
  'c': lambda x: x - 2
}[value](x)
Posted by: Guest on July-11-2021

Code answers related to "function to switch dictionary keys and values"

Python Answers by Framework

Browse Popular Code Answers by Language