0
How to sort versions in python?
4 Answers
+ 5
[edited] JeeV4n NaiK , now i understood what you are going to achieve. the numbers are software version numbers, that should be sorted.
this should work:
inp = ["1.11","2.0.0","1.2","2","0.1","1.2.1","1.1.1","2.0"]
# target Output: 0.1,1.1.1,1.11,1.2,1.2.1,2,2.0,2.0.0
print(*sorted(inp),sep=',')
# output is : 0.1,1.1.1,1.11,1.2,1.2.1,2,2.0,2.0.0
+ 5
JeeV4n NaiK , your question is not very clear. Can you please elaborate the question and get a bit more specific? Thanks!
0
Input: ["1.11","2.0.0","1.2","2","0.1","1.2.1","1.1.1","2.0"]
Output: 0.1,1.1.1,1.11,1.2,1.2.1,2,2.0,2.0.0
I have discovered this challenge in google foobar.
0
Input is in string, i want sorted answer in the output as shown. not in string format.