冒泡排序: l = [9,4,8,7,6,4,7,2,0] def bubble(li): l_len = len(li) print(l_len) for i in range(l_len-1,0,-1): # 注意这里的-1,递减1 print('.') for j in range(0,i): temp = 0 if li[j] > li[j+1]: temp = li[j] li[j] = li[j+1] li[j+1] = temp print(li) return li print(bubble(l)) 2019-6-11 面试题: 给列表中的字典按照age排序
alist = [{'name':'a','age':13},{'name':'s','age':12},{'name':'d','age':11},{'name':'f','age':18},] print(sorted(alist,key=lambda x:x['age']))