code: def _represent_ordereddict(dump, tag, mapping, flow_style=None):
      
      value = []
      node = yaml.MappingNode(tag, value, flow_style=flow_style)
      if dump.alias_key is not None:
          dump.represented_objects[dump.alias_key] = node
      best_style = True
      if hasattr(mapping, 'items'):
          mapping = mapping.items()
      for item_key, item_value in mapping:
          node_key = dump.represent_data(item_key)
          node_value = dump.represent_data(item_value)
          if not (isinstance(node_key, yaml.ScalarNode) and
                  not node_key.style):
              best_style = False    # pylint: disable=bad-indentation
          if not (isinstance(node_value, yaml.ScalarNode) and
                  not node_value.style):
              best_style = False    # pylint: disable=bad-indentation
          value.append((node_key, node_value))
      if flow_style is None:
          if dump.default_flow_style is not None:
              node.flow_style = dump.default_flow_style
          else:
              node.flow_style = best_style
      return node
docs: PyYAML representer function for OrderedDict.
      This is needed for yaml.safe_dump() to support OrderedDict.
  
      Courtesy:
      https://blog.elsdoerfer.name/2012/07/26/make-pyyaml-output-an-ordereddict/