zoukankan      html  css  js  c++  java
  • 内置函数补充(zip map filter)


    1.#zip
    l1 = ['a','b','c','e','f','g']
    l2 = [1,2,3]
    打印出来
    a 1
    b 2
    c 3
    l3=['A','B','C']
    L4=['牛','牛','niu']
    #zip,就是把俩list,合并到一起,变成一个二维数组。如果想同时循环2个list的时候,
    for a,b,c,d in zip(l1,l2,l3,L4):
    print(a,b,c,d)


    2.
    #map #她是帮你循环调用函数
    # def my(num):
    # return str(num)
    # lis = [1,2,3,4,5,6,7,8,9]
    # res = list(map(my,lis)) 与下面结果一样
    # print(res)

    # new_lis = []
    # for i in lis:
    # new_lis.append(my(i))

    3.#filter 也是帮你循环调用函数的,过滤

    def even(num):
    if num%2==0:
    return True
    return False
    lis = [1,2,3,4,5,6,7,8,9]
    res = filter(even,lis)
    print('filter..',list(res)) #filter只保留,返回为真的数据 2 4..
    res2 = map(even,lis)
    print('map..',list(res2)) #map是帮你循环调用函数,这个函数返回就保存什么。flae 和 true
    #结果是什么,它和map和的结果有什么区别
  • 相关阅读:
    Python2 cmp() 函数
    Python round() 函数
    Python floor() 函数
    Python ceil() 函数
    Python abs() 函数
    Python oct() 函数
    Python ord() 函数
    Python hex() 函数
    Python2 unichr() 函数
    Android--------工具类StatusBarUtil实现完美状态栏
  • 原文地址:https://www.cnblogs.com/cslw5566/p/9043742.html
Copyright © 2011-2022 走看看