zoukankan      html  css  js  c++  java
  • python map的学习笔记

    map

    # map(function, iterable, ...) function -- 函数  iterable -- 一个或多个序列
     # Python 2.x
            # 返回列表。
        # Python3.x
            # 返回迭代器。
        #map会把iterable里的值依次放入function执行,返回迭代器

    res = map(lambda x, y: (x ** y, x + y), [2, 4, 6], [3, 2, 1]) print(tuple(res)) # ((8, 5), (16, 6), (6, 7)) print(tuple(res)) # () 注意map内部使用了迭代器,再次使用就为空了 res = map(lambda x, y: (x ** y, x + y), [2, 4, 6], [3, 2, 1]) #map多数以lambda表达式配合使用,简单粗暴 _res = tuple(res) print(_res) # 将它赋值给一个变量来存储 a = [2, 3, 4, 5, 1, 1, 2] b = [3, 42, 3, 4, 32, 2] def func(x, y): if x or y: return x * y return 0 res = list(map(func, a, b)) # 多变量传参 print(res) # [6, 126, 12, 20, 32, 2]
  • 相关阅读:
    allocator类
    智能指针shared_ptr
    字面值常量类
    转换构造函数
    委托构造函数
    访问说明符&封装
    const成员函数
    函数指针
    constexper和常量表达式
    函数返回数组指针
  • 原文地址:https://www.cnblogs.com/RainBol/p/13716865.html
Copyright © 2011-2022 走看看