Ho anche risolto è domanda utilizzando Python, anche se la mia versione fa alcune cose in più, qui è il mio codice:
def answer(l):
list1 = [] # this is the list for the nested strings
for x in l:
list1.append(x.split("."))
list2 = [] # this is the same list as list one except everything is an integer in order for proper sorting
for y in list1:
y = map(int, y)
list2.append(y)
list3 = sorted(list2) #this is the sorted list of of list 2
FinalList = [] # this is the list that converts everything back to the way it was
for a in list3:
a = '.'.join(str(z) for z in a)
FinalList.append(a)
return FinalList
Per le versioni esistono tre cose; Maggiore, minore e revisione. Ciò che fa è che lo organizza in modo che '1'
arriverà prima dello '1.0'
che verrà prima dello '1.0.0'
. Inoltre, un altro vantaggio, non c'è bisogno di importare alcuna libreria nel caso in cui non ce l'hai, e funziona con le vecchie versioni di Python, questo era specificamente pensato per la versione 2.7.6. Comunque, ecco alcuni esempi:
Inputs:
(string list) l = ["1.1.2", "1.0", "1.3.3", "1.0.12", "1.0.2"]
Output:
(string list) ["1.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"]
Inputs:
(string list) l = ["1.11", "2.0.0", "1.2", "2", "0.1", "1.2.1", "1.1.1", "2.0"]
Output:
(string list) ["0.1", "1.1.1", "1.2", "1.2.1", "1.11", "2", "2.0", "2.0.0"]
Se avete domande, basta commentare la risposta !!
Correlati [Come confrontare le stringhe "version-style"] (http://stackoverflow.com/q/11887762) –