Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 在 Python 中,如何自然地对字母数字字符串列表进行排序,以使字母字符排在数字字符之前?
如何在python中对包含数字和字符的字符串进行排序?
>>> s = '13abc3' >>> ''.join(sorted(s, key=lambda x: int(x) if x.isdigit() else x)) '133abc'
如果这是您所追求的,这不会处理任何自定义排序(这是数字,大写,小写)。