Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1516f3acf444dc252e5a to your computer and use it in GitHub Desktop.
Save anonymous/1516f3acf444dc252e5a to your computer and use it in GitHub Desktop.

I have an example YAML file:

---
foo:
  - 1
  - 2
  - 3

bar: test123
lol: test456
haha: test789

And I want to import it and sort the foo, bar, lol, and haha keys has they're specified in said YAML file, like this:

foo
bar
lol
haha

Unfortunately, when reading and loading YAML data in Python 3, the order of the foo, bar, lol, and haha keys will vary:

Like this:

bar
foo
haha
lol

Or like this:

lol
haha
bar
foo

MAKE THE MADNESS STOP!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment