Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Last active August 29, 2015 14:06
Show Gist options
  • Save yuheiomori/799b9969bbe4799d8185 to your computer and use it in GitHub Desktop.
Save yuheiomori/799b9969bbe4799d8185 to your computer and use it in GitHub Desktop.
version number comparison
from distutils.version import StrictVersion
# バージョン番号の比較
print StrictVersion("11.0.0") > StrictVersion("2.0.0")
# => True
# バージョン番号のソート
tests = [
"1.0",
"1.1",
"1.0.1",
"1.0.2",
"1.1.1",
"1.1.2",
"2.0.0",
"11.0.0"
]
print sorted(tests)
# => ['1.0', '1.0.1', '1.0.2', '1.1', '1.1.1', '1.1.2', '11.0.0', '2.0.0']
print sorted(tests, key=StrictVersion)
# => ['1.0', '1.0.1', '1.0.2', '1.1', '1.1.1', '1.1.2', '2.0.0', '11.0.0']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment