a = [1,2,3,4,5]
la = lambda x:x+2
# map是python内置函数,会根据提供的函数对指定的序列做映射
b = map(la,a)
list(b)
[3, 4, 5, 6, 7]
a = [1,2,3]
# iter() 函数用来生成迭代器
c = iter(a)
next(c)
1
next(c)
2
next(c)
3
# 迭代完会报异常
next(c)
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-13-e846efec376d> in <module>
----> 1 next(c)
StopIteration:
la = lambda x:x%2==1
# filter函数是一个python的内置函数,用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象 filter
f = filter(la,a)
list(f)
[1, 3, 5]