---恢复内容开始---

1.map

1)map其实相当对吧运算符进行一个抽象,返回的是一个对象,但是这里不知道为什么不可以对一个map返回变量打印两次,难道是因为回收了?

def f(x):
    return x*x

tmp = map(f,range(6))
tmps = map(str,range(6))
print (list(tmp))
#print (list(tmps))
print (type(range(6)))#range返回的就是range类型<class 'range'>
print (set(tmps))
print(list(tmps))#此时的输出不在是range6的List而是一个空的[]

2)reduce 需要两个以上的参数才能使用,一般是作用域一个list上的,比如下面的求和

1 tadd = reduce(add,range(6))
2 print (tadd)
3 tadd = reduce(add, [x for x in range(6) if x%2 != 0])
4 print (tadd)
View Code

相关文章:

  • 2021-07-30
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2021-12-10
  • 2021-07-01
猜你喜欢
  • 2021-06-28
  • 2022-01-23
  • 2022-01-22
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案