• Python__内置函数补充


    #Author wangmengzhu

    salaries = {
    'egon':3000,
    'alex':100000,
    'wupeiqi':1000,
    'yuanhao':2000
    }
    # print(list(zip(salaries.values(),salaries.keys())))

    # print(max(list(zip(salaries.values(),salaries.keys()))))

    # print(max(salaries,key = lambda name:salaries[name]))


    ##filter,map,reduce
    names = ['alex','wupeiqi','yuanhao','egon']
    # res = map(lambda x:x + '_SB',names)
    # print(list(res))

    #从functools中导入reduce模块
    from functools import reduce
    # print(reduce(lambda x,y:x + y,range(101)))


    def my_map(seq):
    for item in seq:
    item = item + '_SB'
    yield item
    res1 = my_map(names)
    # print(next(res1))

    def my_map(func,seq):
    for item in seq:
    yield func(item)
    # res1 = my_map(lambda x:x + '_SB',names)
    # print(next(res1))

    ##filter函数
    names = ['alex_SB','wupeiqi','yuanhao','egon']
    # print(list(filter(lambda name:name.endswith('SB'),names)))

    ##eval与exec
    # cmd = 'print(x)'
    # x = 1
    # eval(cmd)
    # eval(cmd,{},{})#第一个大括号表示的是全局作用域,第二个大括号表示的是局部作用域
    # eval(cmd,{'x':0},{'y':10000})

    s = 'for i in range(10):print(i)'
    code = compile(s,'','exec')
    exec(code)
  • 相关阅读:
    修改oracle的sys、system密码
    错误随手笔记
    JS 全选
    ider向虚拟机上传jar包
    Spring中的八大设计模式
    事务的隔离级别
    hive常用函数全集
    Kafka常用命令
    字符设备驱动框架学习总结
    根文件系统熟悉(一)根文件系统构建过程记录
  • 原文地址:https://www.cnblogs.com/wangmengzhu/p/7299498.html
Copyright © 2020-2023  润新知