Input :- {34: 'apple', 65: 'ball', 32: 'cat', 78: 'dog'}
Output :- {34: 'dog', 65: 'apple', 32: 'ball', 78: 'cat'}
I have come up with the following approach but is there any faster way to perform this task?
def rotate_values(my_dict):
keys_list = list(my_dict.keys())
values_list = list(my_dict.values())
values_list.insert(0, values_list.pop())
my_dict = dict(zip(keys_list, values_list))
return my_dict