zoukankan      html  css  js  c++  java
  • python 快速写作技巧,格式

    # coding:utf-8

    # 111111111111111快速生成

    # 快速生成字典

    a= dict(zip("abcd", range(4)))

    print(a)

    # 按照条件快速输出

    b= 11

    print("ok" if b== 1 else "ko")

    # 2222222222222快速排序

    # 快速输出前几名

    import heapq

    nums= [1, 2, 3, 4, 56, 77, 88, 99]

    print(heapq.nlargest(3, nums))  # 最大的前三名

    print(heapq.nsmallest(3, nums))  # 最小的前三名

    students= [{"name": "aa", "age": 15, "score": 100},

                {"name": "bb", "age": 16, "score": 90},

                {"name": "cc", "age": 17, "score": 80}

    ]

    # 按照某个key排序

    print(heapq.nsmallest(2, students, key=lambda z: z["age"]))

  • 相关阅读:
    SRM482
    SRM481
    SRM480
    SRM479
    SRM478
    vue-cli 3 is not a modual err
    .vimrc
    css3 导入字体
    class []的用法
    RK61 Keyboard Use
  • 原文地址:https://www.cnblogs.com/waterstar/p/11320924.html
Copyright © 2011-2022 走看看