def ordered_dump(data, stream=None, Dumper=yaml.Dumper, **kwds):


    class OrderedDumper(Dumper):
        pass

def _dict_representer(dumper, data):
    return dumper.represent_mapping(yaml.resolver.BaseResolver.
        DEFAULT_MAPPING_TAG, list(data.items()))
OrderedDumper.add_representer(OrderedDict, _dict_representer)
return yaml.dump(data, stream, OrderedDumper, **kwds)
ordered_dump(data, Dumper=yaml.SafeDumper)
In Python, how can you load YAML mappings as OrderedDicts?