Sorting a list of version strings

Posted by Zack on Stack Overflow See other posts from Stack Overflow or by Zack
Published on 2010-04-04T09:51:57Z Indexed on 2010/04/04 9:53 UTC
Read the original article Hit count: 259

Filed under:

I have a list containing version strings, such as things:

versions_list = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"]

I would like to sort it, so the result would be something like this:

versions_list = ["1.0.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"]

The order of precendece for the digits should obviously be from left to right, and it should be decending. So 1.2.3 comes before 2.2.3 and 2.2.2 comes before 2.2.3.

How do I do this in Python?

© Stack Overflow or respective owner

Related posts about python