zoukankan      html  css  js  c++  java
  • sorted排序

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

      

  • 相关阅读:
    【NOI2015】荷马史诗
    Codeforces Round #415 (Div. 2)
    Codeforces Round #408 (Div. 2)
    bzoj3230
    poj1743
    poj1226
    bzoj1295
    bzoj1294
    bzoj1296
    bzoj1239
  • 原文地址:https://www.cnblogs.com/vonkimi/p/6896470.html
Copyright © 2011-2022 走看看