Skip to main content

Python List Of Dictionary sorting with key as Versions

  from distutils.version import StrictVersion

versions = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"]
versions.sort(key=StrictVersion,reverse=True)

output : ['1.3.3', '1.1.2', '1.0.12', '1.0.2', '1.0.0']


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)

output: [{'ver': '1.3.3'}, {'ver': '1.1.12'}, {'ver': '1.0.12'}, {'ver': '1.0.2'}, {'ver': '1.0.0'}]

You can see GIT Snippet on this codelink

Comments

  1. Thank you for sharing your information. It is really nice blog.
    Best civil engineering college in Jaipur

    ReplyDelete
  2. As claimed by Stanford Medical, It is indeed the ONLY reason this country's women live 10 years more and weigh an average of 19 KG lighter than we do.

    (And actually, it is not related to genetics or some secret diet and EVERYTHING to do with "HOW" they are eating.)

    BTW, I said "HOW", not "WHAT"...

    Tap on this link to uncover if this little quiz can help you discover your true weight loss potential

    ReplyDelete

Post a Comment