I have a list of strings I want to natural sort:
c = ['0', '1', '10', '11', '2', '2Y', '3', '3Y', '4', '4Y', '5', '5Y', '6', '7', '8', '9', '9Y']
In addition to natural sort, I want to move all entries that are not pure number strings to the end. My expected output is this:
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '2Y', '3Y', '4Y', '5Y', '9Y']
Do note that everything has to be natsorted - even the alphanumeric strings.
I know I can use the natsort package to get what I want, but that alone does not do it for me. I need to do this with two sort calls - one to natural sort, and another to move non-pure numeric strings to the end.
import natsort as ns
r = sorted(ns.natsorted(c), key=lambda x: not x.isdigit())
print(r)
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '2Y', '3Y', '4Y', '5Y', '9Y']
I'd like to know if it's possible to use natsort in a crafty manner and reduce this to a single sort call.