开发者社区> 问答> 正文

python必备内置函数- map(function, iterable, …)

python必备内置函数- map(function, iterable, …)

展开
收起
请回答1024 2020-03-30 11:38:06 365 0
1 条回答
写回答
取消 提交回答
  • 返回一个将 function 应用于 iterable 中每一项并输出其结果的迭代器:

    In [85]: list(map(lambda x: x%2==1, [1,3,2,4,1]))
    Out[85]: [True, True, False, False, True]
    
    

    可以传入多个iterable对象,输出长度等于最短序列的长度:

    In [88]: list(map(lambda x,y: x%2==1 and y%2==0, [1,3,2,4,1],[3,2,1,2]))
    Out[88]: [False, True, False, False]
    
    2020-03-30 11:38:30
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载