我试着使用匿名函数filter()
的许多不同的例子,但只要我在字符串上使用它,总会得到奇怪的结果。下面是一个例子:是否在Python 2.x和3.x之间更改了`filter()`?
>>>print(filter(lambda x: x.isdigit(), "aas30dsa20"))
<filter object at 0x00000000035DE470>
如果不是字符串,一切工作正常。例如;
>>> print(list(filter(lambda x: x >= 30 and x <= 70, [x**2 for x in range(1,11)])))
[36, 49, 64]
顺便说一句,如果我删除list()
功能部分,会出现类似于字符串大小写问题:
>>> print(filter(lambda x: x >= 30 and x <= 70, [x**2 for x in range(1,11)]))
<filter object at 0x00000000037BFDD8>
我使用Python 3.4.1在Windows 7
总之:[是](https://docs.python.org/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists)。 – jonrsharpe