sorted()函数

版权声明:转载请标明出处 https://blog.csdn.net/gymaisyl/article/details/83039321

sorted() 函数

  • sorted( iterable, key, reverse)
    (1)iterable:是可迭代类型的数据;
    (2)key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一项;
    (3)reverse:排序规则. reverse = True 或者 reverse = False,有默认值,默认为升序排列False
官方关于这个函数的解释:
def sorted(*args, **kwargs): # real signature unknown
 """
 Return a new list containing all items from the iterable in ascending order.
 
 A custom key function can be supplied to customize the sort order, and the
 reverse flag can be set to request the result in descending order.
 """
 pass

关于其中的英文注释,翻译过来就是:

①以升序返回包含iterable中所有项的新列表。
②可以提供自定义键功能来自定义排序顺序,以及 可以设置反向标志以按降序请求结果。

关于使用方法,可以参考字典排序中的使用,链接如下:
https://blog.csdn.net/gymaisyl/article/details/83039279

猜你喜欢

转载自blog.csdn.net/gymaisyl/article/details/83039321