Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. a = ['0.jpg', '1.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg', '16.jpg', '17.jpg', '18.jpg', '19.jpg', '2.jpg', '20.jpg', '21.jpg', '22.jpg', '23.jpg', '24.jpg', '25.jpg', '26.jpg', '27.jpg', '28.jpg', '29.jpg', '3.jpg', '30.jpg', '31.jpg', '32.jpg', '33.jpg', '34.jpg', '35.jpg', '36.jpg', '37.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg']
  2.  
  3. import re
  4. def natural_sort(l):
  5. convert = lambda text: int(text) if text.isdigit() else text.lower()
  6. alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
  7. return sorted(l, key = alphanum_key)
  8.  
  9. o = natural_sort(a)
  10. print o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement