code: def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
      
  
      # noinspection PyClassHasNoInit
      class OrderedLoader(Loader):
          """
          A helper class to define an Ordered Loader
          """
          pass
  
      def construct_mapping(loader, node):
          """
          construct a flattened node mapping
          :param loader: the loader
          :param node: the node dict
          :return: 
          """
          loader.flatten_mapping(node)
          return object_pairs_hook(loader.construct_pairs(node))
  
      OrderedLoader.add_constructor(
          yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
          construct_mapping)
      return yaml.load(stream, OrderedLoader)
docs: Loads an ordered dict into a yaml while preserving the order
  
      :param stream: the name of the stream
      :param Loader: the yam loader (such as yaml.SafeLoader)
      :param object_pairs_hook: the ordered dict