>>> n = [1,2,3,4]
>>> filter(lambda x:x>3,n)
<filter object at 0x0000000002FDBBA8>
>>> len(filter(lambda x:x>3,n))
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
len(filter(lambda x:x>3,n))
TypeError: object of type 'filter' has no len()
我无法得到我得到的列表的长度。所以我尝试将它保存到一个变量中,就像这样......
>>> l = filter(lambda x:x>3,n)
>>> len(l)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
len(l)
TypeError: object of type 'filter' has no len()
而不是使用循环,有什么办法可以得到这个的长度?