code: def sort_dict(d: dict, by: str = 'key',
                allow_duplicates: bool = True) -> collections.OrderedDict:
      if by == 'key':
          i = 0
      elif by == 'value':
          values = list(d.values())
          if len(values) != len(set(values)) and not allow_duplicates:
              duplicates = find_duplicates(values)
              raise ValueError("There are duplicates in the values: {}".format(duplicates))
          i = 1
      else:
          raise ValueError("by can be 'key' or 'value'.")
      return collections.OrderedDict(sorted(d.items(), key=lambda t: t[i]))