Python analog of PHP’s natsort function (sort a list using a “natural order” algorithm)

I would like to know if there is something similar to PHP natsort function in Python? l = ['image1.jpg', 'image15.jpg', 'image12.jpg', 'image3.jpg'] l.sort() gives: ['image1.jpg', 'image12.jpg', 'image15.jpg', 'image3.jpg'] but I would like to get: ['image1.jpg', 'image3.jpg', 'image12.jpg', 'image15.jpg'] UPDATE Solution base on this link def try_int(s): "Convert to integer if possible." try: return int(s) except: … Read more