Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort list in python by substring

mylist = ['XYZ-78.txt', 'XYZ-8.txt', 'XYZ-18.txt'] 
print(sorted(mylist, key=lambda x: int(x.split("-")[-1].split(".")[0])))
Source by www.thetopsites.net #
 
PREVIOUS NEXT
Tagged: #sort #list #python #substring
ADD COMMENT
Topic
Name
2+4 =