filter(函数,可以迭代的对象)
1 #!/usr/bin/env python 2 #filter(函数,可以迭代的对象) 3 4 def f1(x): 5 if x > 22: 6 return True 7 else: 8 return False 9 10 11 ret = filter(f1, [11,22,33,44]) 12 #相当于ret = filter(lambda x: x > 22,[11,22,33,44]) 13 for i in ret: 14 print(i)
结果:
C:\Python35\python3.exe F:/Python/2day/c1.py 33 44 Process finished with exit code 0