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------------------

 

 

 

posted @ 2017-09-26 21:54  王思聪6  阅读(187)  评论(0编辑  收藏  举报
友情链接:回力球鞋 | 中老年高档女装