I have a list of strings:
[song_1, song_3, song_15, song_16, song_4, song_8]
I would like to sort them by the # at the end, unfortunately s
def number_key(name): parts = re.findall('[^0-9]+|[0-9]+', name) L = [] for part in parts: try: L.append(int(part)) except ValueError: L.append(part) return L sorted(your_list, key=number_key)