Hey Guys.
Trying to add value, key in this order to a dictionary.
Checking with the debugger it shows that index 0 is added to new_dict, and then in the second iteration, index 1 replaces index 0 and then index 2 is added correctly.
Any idea why?
Trying to add value, key in this order to a dictionary.
Checking with the debugger it shows that index 0 is added to new_dict, and then in the second iteration, index 1 replaces index 0 and then index 2 is added correctly.
Any idea why?
course_dict = {'I': 3, 'love': 3, 'self.py!': 2}
def inverse_dict(my_dict):
new_dict = {}
for key, value in my_dict.items():
new_dict.update({value: key})
return new_dict
print(inverse_dict(course_dict))
