11 lines
376 B
Python
11 lines
376 B
Python
#map(函数,不定长迭代器) map函数
|
|
#题目要求:已知列表[1,2,3,4,5,6,7,8,9],请你返回一个x*x的列表.
|
|
li=[1,2,3,4,5,6,7,8,9]
|
|
print(list(map(lambda x:x*x,li)))
|
|
|
|
#导入functools,才可使用reduce函数
|
|
#functools.reduce(函数对象,序列,初始数据)
|
|
import functools
|
|
list1=["a","b","c","Python"]
|
|
print(functools.reduce(lambda a,b:a+b,list1,"Hello"))
|