码迷,mamicode.com
首页 > 编程语言 > 详细

sorted排序

时间:2017-05-23 22:47:27      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ever   blog   lis   from   pytho   highlight   item   rom   end   

排序函数sorted原型如下,接受一个可迭代的序列,可以自定义排序函数放在key中,可以对待排序序列先期进行处理,还可以指定正反序

sorted(iterable, /, *, key=None, reverse=False)
Return a new list containing all items from the iterable in ascendi

A custom key function can be supplied to customize the sort order,
reverse flag can be set to request the result in descending order.

 

作业:

L = [(‘Bob‘, 75), (‘adam‘, 92), (‘Bart‘, 66), (‘Lisa‘, 88)]
def by_name(t):
    return str.lower(t[0])

L2 = sorted(L, key=by_name)
print(L2)

  

sorted排序

标签:ever   blog   lis   from   pytho   highlight   item   rom   end   

原文地址:http://www.cnblogs.com/vonkimi/p/6896470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!