habe ich auch th gelöst mein Code Frage Python verwenden, obwohl meine Version einige zusätzliche Dinge tut, ist hier:
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
Für Versionen gibt es drei Dinge; Major, Minor und die Überarbeitung. Was dies tut ist, dass es es organisiert, so dass '1'
vor '1.0'
kommt, die vor '1.0.0'
kommen wird. Ein weiterer Pluspunkt ist, dass Sie keine Bibliotheken importieren müssen, wenn Sie sie nicht haben, und es funktioniert mit alten Versionen von Python, die speziell für Version 2.7.6 gedacht waren. Wie auch immer, hier sind ein paar Beispiele:
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"]
Wenn Sie Fragen haben, kommentieren Sie einfach die Antwort !!
Ähnliche [Wie man "version-style" Zeichenfolgen vergleicht] (http://stackoverflow.com/q/11887762) –