汉语:Python 是工程开发中的利器。需要多加训练。
E-version:python is popular in project dev。so everyone should practice more.
如题:
AS-LIKE
''' 功能:根据内嵌的数字将字符串排序 输入:alist 原始字符串列表 输出:无 返回:排序结束后的列表,按从小到大排序 '''
input :["a11","12cs", "c10s" ]
output: ["c10s","a11","12cs"]
实现:
import re
def sort(self, alist):
return [r[1] for r in sorted(zip([int(re.sub("\D","", a)) for a in alist],[b for b in alist]))]
# 也可以 return sorted(alist, key=lambda x: int(re.search('\d+', x).group(0)))