def natural_sort_key(cls, value):
"""
This is a sort key to do a "natural" lexographic sort, the string is
broken up into segments of strings and numbers, so that, e.g. `'Str 2'`
will be sorted before `'Str 15'`.
:param value:
The book name as it will be sorted.
:return:
Returns a book name tokenized such that it can be sorted.
"""
o = itertools.groupby(value, key=str.isdigit)
o = ((k, ''.join(g)) for k, g in o)
o = ((int(v) if k else v) for k, v in o)
return tuple(o)
评论列表
文章目录