首页 > 编程语言 > 详细

sorted排序

时间:2017-05-23 22:24:40      阅读:367      评论:0      收藏:0      [点我收藏+]

排序函数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排序

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!