sort list in python by substring

Solutions on MaxInterview for sort list in python by substring by the best coders in the world

showing results for - "sort list in python by substring"
Gauthier
08 Aug 2020
1mylist = ['XYZ-78.txt', 'XYZ-8.txt', 'XYZ-18.txt'] 
2print(sorted(mylist, key=lambda x: int(x.split("-")[-1].split(".")[0])))