In [1]: def grp(pat, txt): ...: r = re.search(pat, txt) ...: return r.group(0) if r else '&'In [2]: yOut[2]: ['random text random text, can be anything blabla %A blabla', 'random text random text, can be anything blabla %D blabla', 'random text random text, can be anything blabla blabla %F', 'random text random text, can be anything blabla blabla', 'random text random text, %C can be anything blabla blabla']In [3]: y.sort(key=lambda l: grp("%w", l))In [4]: yOut[4]: ['random text random text, can be anything blabla %A blabla', 'random text random text, %C can be anything blabla blabla', 'random text random text, can be anything blabla %D blabla', 'random text random text, can be anything blabla blabla %F', 'random text random text, can be anything blabla blabla']
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)