I am trying to check some internal yaml files, and "fix" them. For that I need to preserve the comments, so I decided to use raumel.yaml library. The thing is that one of the checks is that some "keys", if present, are in a certain order. So for example: settings: # foo key2: prop: value # bar key1: prop: value ... I need to "fix" it, like this: settings: # bar key1: prop: value # foo key2: prop: value ... but in order to check first the correct "order", I am wondering if I do the following: yaml = YAML() yaml.preserve_quotes = True file: CommentedMap = yaml.load(path) settings: Any = file.get("settings", default=[]) if not isinstance(linters, CommentedMap): return keys: list[str] = list(settings.keys()) # are keys keeping the insertion order? ... keys will keep the insertion order. Thanks. Continue reading...