zoukankan      html  css  js  c++  java
  • python 内置&&递归

    lambda

    优点:

    1:可以简单使用一个脚本来替代我们的函数

    2:不用考虑命名的问题

    3:简化代码的可读性,不用跳转到def了,省去这样的步骤

    内置函数:bif

    filter:过滤器

    map:映射

     1 >>> lambda x: 2*x+1
     2 <function <lambda> at 0x00000000026C6AC8>
     3 >>> g=lambda x: 2*x+1
     4 >>> g(3)
     5 7
     6 >>> help(filter)
     7 Help on built-in function filter in module __builtin__:
     8 
     9 filter(...)
    10     filter(function or None, sequence) -> list, tuple, or string
    11     
    12     Return those items of sequence for which function(item) is true.  If
    13     function is None, return the items that are true.  If sequence is a tuple
    14     or string, return the same type, else return a list.
    15 
    16 >>> filter(None,[1,0,True,False])
    17 [1, True]
    18 >>> 
    19 >>> 
    20 >>> tmp=range(10)
    21 >>> tmp
    22 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    23 >>> def fun(x):
    24     return x%2
    25 
    26 >>> filter(fun,tmp)
    27 [1, 3, 5, 7, 9]
    28 >>> list(filter(lambda x:x%2,range(10)))
    29 [1, 3, 5, 7, 9]
    30 >>> list(map(lambda x:x*2,range(10)))
    31 [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
    32 >>> 

    递归

    python限制的递归深度大概几百层,但是可以手动设置

    》》》import sys

    >>> sys.setrecursionlimit(10000)

    python---------------------------------------eg'1------------------

     

  • 相关阅读:
    矩阵分析 p13~p20
    矩阵分析 p1~p13
    复变函数2
    口语80篇(1-2)
    复变函数1
    背单词方法
    writing practice
    将博客搬至CSDN
    windows内核编程 白话设备栈
    sfliter__except_handler4
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6047277.html
Copyright © 2011-2022 走看看