【发布时间】:2017-12-18 08:48:35
【问题描述】:
我的印象是下面的代码:
filter(None,"Stack Overflow")
会返回:
"StackOverflow"
但是当我使用 Python (2.7) 时,这并没有发生。谁能告诉我为什么会这样?
【问题讨论】:
-
在 python 3 上,
filter返回一个生成器对象。所以你必须使用''.join(filter... -
见docs
If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
标签: python python-2.7 filter