I wrote the following code and i cannot understand why my dictionary is being deleted alone with my list. Really hope you could help me with it.. iam kind of stuck here.
This is my code :
course_dict = {'I': 3, 'love': 3, 'self.py!': 2}
save_dict = {}
def inverse_dict(Recived_dict):
global save_dict
list_counter = 0
new_dict = {}
my_list = []
current_value = list(Recived_dict.values())[0]
for key, value in Recived_dict.items():
if value == current_value:
my_list.append(key)
new_dict[value] = my_list
save_dict = new_dict
else:
if list_counter == 0:
del my_list[0:]
list_counter =1
my_list.append(key)
new_dict[value] = my_list
print(new_dict)
inverse_dict(course_dict)