过滤掉不满足条件的信息
>>> import math
>>> def is_sqr(x):
... return math.sqrt(x) % 1 == 0
...
>>> a = filter(is_sqr, range(1, 20))
>>> print(a)
<filter object at 0x1017d95c0>
>>> for item in a:
... print(item)
...
1
4
9
16
过滤掉不满足条件的信息
>>> import math
>>> def is_sqr(x):
... return math.sqrt(x) % 1 == 0
...
>>> a = filter(is_sqr, range(1, 20))
>>> print(a)
<filter object at 0x1017d95c0>
>>> for item in a:
... print(item)
...
1
4
9
16