Answers for "flip keys and values in dictionary python"

2

switching keys and values in a dictionary in python [duplicate]

my_dict = {2:3, 5:6, 8:9}

new_dict = {}
for k, v in my_dict.items():
    new_dict[v] = k
Posted by: Guest on February-16-2020
0

convert keys to values in python

old_dict = {'A': 67, 'B': 23, 'C': 45, 'D': 56, 'E': 12, 'F': 69, 'G': 67, 'H': 23} 
  
new_dict = dict([(value, key) for key, value in old_dict.items()])
print(new_dict)
for i in new_dict: 
    print(i, " :  ", new_dict[i])
Posted by: Guest on July-28-2020

Code answers related to "flip keys and values in dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language