Construct a function in Python to compare the two given dictionaries and return true if both of them contains the same elements.
dict1 = {'A':1, 'B':2, 'C':3 }
dict2 = {'A':1, 'C':3, 'B':2 }
def compare_dicts(dict1, dict2):
  # Iterate through keys in both dictionaries and compare values
  for key, value in dict1.items():
    if key not in dict2 or dict2[key] != value:
      return False
 
  # If all elements matched
  return True