zoukankan      html  css  js  c++  java
  • python -高阶函数

    '''map(fun,[1,23,4])函数第一个参数是函数,第二个参数是集合,
    运行的时候,会把集合中的每一个元素放到前面的函数当中,并且函数有返回值,形成一个新的集合需要
    list 或者tuple

    '''

    def fun(x):
    return x**2
    list1 = list(map(fun,[1,2,3]))
    list2 = list(map(lambda x:x**2 ,[1,2,3]))
    str1 = list(map(str,(1,2,4)))
    print(''.join(list2))
    print(str1)



    '''sorted(集合,key=fun) 顺序不能反了'''

    dict1 = {'a':1,'b':2,'d':4,'c':3}
    '''把字典按值进行排序'''
    def fun1(x):
    return x[1]


    print(sorted(dict1.items(),key=fun1))
  • 相关阅读:
    第四次
    jsp
    2021.3.4
    第八次作业
    第七次作业
    第六周作业
    第五周作业
    第四周
    第四次jsp作业
    第二次作业
  • 原文地址:https://www.cnblogs.com/tarzen213/p/11093490.html
Copyright © 2011-2022 走看看