python list 字符串排序

#coding:utf-8
import re
s = ['dat2','dat10','dat5']
#方法一
new = sorted(s,key = lambda i:int(re.search(r'(\d+)',i).group()))
print new

#方法二
s.sort(key=lambda i:int(re.search('(\d+)', i).group()))
print s

sorted(iterable, cmp=None, key=None, reverse=False)

sort(cmp=None, key=None, reverse=False)

posted @ 2018-04-24 15:52  LLSix  阅读(639)  评论(0编辑  收藏  举报