Способ 1:
from pkg_resources import parse_version
def test_version_sorting():
expected = ['1.0.0dev0',
'1.0.0dev1',
'1.0.0dev2',
'1.0.0dev10',
'1.0.0rc0',
'1.0.0rc2',
'1.0.0rc5',
'1.0.0rc21',
'1.0.0',
'1.1.0',
'1.1.1',
'1.1.11',
'1.2.0',
'1.3.0',
'1.23.0',
'2.0.0', ]
alphabetical = sorted(expected)
shuffled = sorted(expected, key=lambda x: random())
assert expected == sorted(alphabetical, key=parse_version)
assert expected == sorted(shuffled, key=parse_version)
Способ 2:
>>> from distutils.version import LooseVersion
>>> versions = ["1.7.0", "1.7.0rc0", "1.11.0"]
>>> sorted(versions, key=LooseVersion)
['1.7.0', '1.7.0rc0', '1.11.0']