26 Jun 2009

Sorting dicts of dicts

So, say you’ve got these dicts of files and metadata that, for whatever reason, you need in a dict. What if you need to sort that list while maintaining key/value pairs? (I know that this example is contrived, but I actually have this problem in something I’m working on)

Itemgetter will do you just fine if you don’t need the key/value pairs to be maintained, but if you need the pairs intact, a lambda will do the same job for you.