面试笔试

(1)[11, 33, 4, 2, 11, 4, 9, 2]去重并保持原来的顺序?

li = [11,33,4,2,11,4,9,2]
set1 = list(set(li))
ret = sorted(set1,key=li.index)
print(ret)
 
(2)按照年龄进行排序
list = [
    {'name':'金老板',"age":30},
    {"name":"景女神","age":16},
    {'name':"mjj","age":26}
]

ret = sorted(list,key=lambda x:x['age'])
print(ret)

 

posted @ 2018-07-29 23:58  Coca-Mirinda  阅读(106)  评论(0编辑  收藏  举报