2

So I have a function that gives me the dictionary in the reverse the order of insertion.

a = {1:2, 2:5, 6:7}

def reverse_dict(dict): 
  reverse_list = list(reversed(list(dict.items())))

  di = {}

  for a, b in reverse_list: 
      di[a] = b 

  return di 

However, If I call the function, my output is the same as the original dictionary but if i print it my output is the desired outcome.

print(reverse_dict(a))
>>> {6: 7, 2: 5, 1: 2}

reverse_dict(a)
>>> {1: 2, 2: 5, 6: 7}


Why is this happening and what is the fix ?

Wu Daozi
  • 51
  • 3

0 Answers0