python filter()和map()函数

mac2022-06-30  25

1.filter(func,iterable)

2.map(func,iterable)

1.filter(func,iterable)filter func要是一个限定第二个参数范围用函数去筛选列表中的内容,符合条件的会留下来 def notemp(s): return s and s.strip()sl=['a','','2','4',None,'b']a=filter(notemp,sl)for i in a: print(i) 2.map(func,iterable)map 的func是如果要判断元素的范围只能返回T or F lis=[1,2,3,4,5,6]r= map(lambda x: x if x>3 else 1,lis) for j in r: print(j)

  

 

转载于:https://www.cnblogs.com/ezway/p/6394896.html

最新回复(0)