rows = [ {'name':'Jack','uid':1003,'level':5}, {'name':'Gigi','uid':1001,'level':2}, {'name':'Koko','uid':1005,'level':3}, {'name':'Eric','uid':1004,'level':2}, {'name':'Aven','uid':1002,'level':6}]
方法一
rows_by_name = sorted(rows, key=lambda r: r['name'])
方法二
from operator import itemgetter
rows_by_name = sorted(rows, key=itemgetter('level'))
参考
https://www.cnblogs.com/jasonminghao/p/13246582.html
网友评论