Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Last active September 25, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vijaysinh/2a6fac38052b12acacfff4c049187f97 to your computer and use it in GitHub Desktop.
Save Vijaysinh/2a6fac38052b12acacfff4c049187f97 to your computer and use it in GitHub Desktop.
Sorting Api Version in python
from distutils.version import StrictVersion
#from operator import itemgetter
v1 = [{'ver': "1.1.12"},{'ver': "1.0.0"},{'ver': "1.3.3"},{'ver': "1.0.12"},{'ver': "1.0.2"}]
v1.sort(key=lambda x: StrictVersion(x['ver']),reverse=True)
print(v1)
versions = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"]
versions.sort(key=StrictVersion,reverse=True)
print(versions)
# v = [{'ver': "1.1.12"},{'ver': "1.0.0"},{'ver': "1.3.3"},{'ver': "1.0.12"},{'ver': "1.0.2"}]
# v.sort(key=itemgetter("ver"),reverse=True)
# print(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment