How to sort a dict by key of versions
<p>Input:</p>

<pre><code>foo = {
    'testing-1.30.5': ['The', 'quick'],
    'testing-1.30.12': ['fox', 'jumped', 'over'],
    'testing-1.30.13': ['the'],
    'testing-1.30.4': ['lazy', 'dog'],
    'testing-1.30.1': ['brown'],
    'testing-1.30.3': ['the'],
    'testing-1.30.6': ['brown'],
    'testing-1.30.2': ['fox', 'jumped', 'over'],
    'testing-1.30.14': ['lazy', 'dog'],
    'testing-1.30.8': ['the'],
    'testing-1.30.0': ['The', 'quick'],
    'testing-1.30.10': ['The', 'quick'],
    'testing-1.30.11': ['brown'],
    'testing-1.30.7': ['fox', 'jumped', 'over'],
    'testing-1.30.9': ['lazy', 'dog']
}
</code></pre>

<p>Do some sorting</p>

<pre><code>bar = sortfoo(foo)
</code></pre>

<p>Desired output:</p>

<pre><code>for item in bar:
    print '{}: {}'.format(item, bar[item])



testing-1.30.0: ['The', 'quick']
testing-1.30.1: ['brown']
testing-1.30.2: ['fox', 'jumped', 'over']
testing-1.30.3: ['the']
testing-1.30.4: ['lazy', 'dog']
testing-1.30.5: ['The', 'quick']
testing-1.30.6: ['brown']
testing-1.30.7: ['fox', 'jumped', 'over']
testing-1.30.8: ['the']
testing-1.30.9: ['lazy', 'dog']
testing-1.30.10: ['The', 'quick']
testing-1.30.11: ['brown']
testing-1.30.12: ['fox', 'jumped', 'over']
testing-1.30.13: ['the']
testing-1.30.14: ['lazy', 'dog']
</code></pre>

<p>Ideally I would like this to be pythonic, in that I wouldn't do something crazy like splitting the key into components and building a new dictionary based off that;</p>

<p>What I tried:</p>

<pre><code>from collections import OrderedDict
od = OrderedDict(sorted(foo.items()))
    print '{}: {}'.format(item, od[item])
</code></pre>

<p>Thank you</p>

<p>Got it! nevermind, found LooseVersion / strict versions</p>

<pre><code>from distutils.version import LooseVersion
from collections import OrderedDict

orderedKeys = sorted(foo, key=LooseVersion)

odict = OrderedDict((key, foo[key]) for key in orderedKeys)

for item in odict:
     print '{}: {}'.format(item, odict[item])
</code></pre>

python sorting dictionary key versions