Answers for "sort list by sublist python"

1

sorting by second element

sorted(LISTNAME, key=lambda x: x[1])
Posted by: Guest on September-24-2020
0

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])))
Posted by: Guest on September-29-2020

Python Answers by Framework

Browse Popular Code Answers by Language