import re
def nautural_order_key(s, _split=re.compile(r'(\d+)').split, conv=int):
it = _split(s)
it[1::2] = map(conv, it[1::2])
return it
x = ['hoge99', 'hoge100', 'hoge10']
x.sort(key= nautural_order_key)
print(x) # ['hoge10', 'hoge99', 'hoge100']
Recommended Posts