0

How to sort versions in python?

20th Aug 2020, 4:10 PM
Jeevan Manjunath Naik
Jeevan Manjunath Naik - avatar
4 odpowiedzi
+ 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
20th Aug 2020, 5:36 PM
Lothar
Lothar - avatar
+ 5
JeeV4n NaiK , your question is not very clear. Can you please elaborate the question and get a bit more specific? Thanks!
20th Aug 2020, 4:43 PM
Lothar
Lothar - avatar
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.
20th Aug 2020, 4:51 PM
Jeevan Manjunath Naik
Jeevan Manjunath Naik - avatar
0
Input is in string, i want sorted answer in the output as shown. not in string format.
20th Aug 2020, 5:19 PM
Jeevan Manjunath Naik
Jeevan Manjunath Naik - avatar