Last active
August 29, 2015 14:06
-
-
Save yuheiomori/799b9969bbe4799d8185 to your computer and use it in GitHub Desktop.
version number comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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