Wow, that works pretty well. I was mistaken in thinking that either the Dictionary class or the process of sampling would sort them.
Mind if I merge that? Or you could submit a pull request. Either would be great!
Also, do you know of any resources for learning about how to optimise for gzip compression? Google is just telling me about compression for websites.