Dumping a dictionary to a YAML file while preserving order
yaml.dump has a sort_keys keyword argument that is set to True by default. Set it to False to not reorder: with open(CaseFile, ‘w’) as f: yaml.dump(lyml, f, default_flow_style=False, sort_keys=False)