I have a list like this
a = ['data/1.jpg','data/10.jpg','data/2.jpg'...]
I want to sort this list like this manner,
['data/1.jpg','data/2.jpg','data/10.jpg'...]
I have tried lots of methods, But it is not working, How I will do?
I have a list like this
a = ['data/1.jpg','data/10.jpg','data/2.jpg'...]
I want to sort this list like this manner,
['data/1.jpg','data/2.jpg','data/10.jpg'...]
I have tried lots of methods, But it is not working, How I will do?
You need to write a function that parses the file names the way you want, and use that as your sort key
. For the example you've given, you could do this:
def key(full_name):
name, _ = full_name.split(".")
name, order = name.split("/")
return name, int(order)
foo = ['data/1.jpg','data/10.jpg','data/2.jpg']
bar = sorted(foo, key=key)