标签: python python-3.x python-2.7
可能重复: In Python, how can I naturally sort a list of alphanumeric strings such that alpha characters sort ahead of numeric characters?
如何在python中对包含数字和字符的字符串进行排序?
答案 0 :(得分:3)
>>> s = '13abc3' >>> ''.join(sorted(s, key=lambda x: int(x) if x.isdigit() else x)) '133abc'
这不会处理任何自定义排序,如果这是您所追求的(这是数字,大写,小写)。