Search
 
SCRIPT & CODE EXAMPLE
 

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])))
Comment

PREVIOUS NEXT
Code Example
Python :: django making a custom 403 page 
Python :: convert a tuple into string python 
Python :: column.replace 
Python :: missingno python 
Python :: python execute time 
Python :: initialize an array in python 
Python :: python export multiple dataframes to excel 
Python :: python make dictionary based on list 
Python :: blank=True 
Python :: dropna for specific column pandas 
Python :: wikipedia python 
Python :: adding numbers using python function 
Python :: how to append data to csv file in python without replacing the already present text 
Python :: dice rolling simulator python 
Python :: delete specific indeces from numpy array 
Python :: load and image and predict tensorflow 
Python :: use datetime python to get runtime 
Python :: blinking an led with raspberry pi 
Python :: sqlite3 python parameterized query 
Python :: python get number of days 
Python :: plt change grid color 
Python :: how to disable resizing in tkinter 
Python :: how to check nth prime in python 
Python :: get title attribute beautiful soup 
Python :: selenium python class contains 
Python :: convert a number column into datetime pandas 
Python :: python 64 bit 
Python :: how do you see if a data type is an integer python 
Python :: python fill 0 
Python :: decorator python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =