我幾乎從在線文檔中給出的例子複製,但在基於Windows的Python 3中使用filter()讓我感到困惑。什麼錯在這裏是:在Python中使用過濾器3
a=[1,2,3,4]
b=[1,0,1,0]
f=filter(b,a)
for fs in f : print(fs)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
f=list(filter(b,a))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
在線文檔說扔在list()
,但清楚地幫助沒有。
你期望得到什麼結果?請注意,「過濾器」與「在這兩個列表中查找這些列表中的元素」不同。「 – Kevin
您指的是哪些在線文檔? [官方文檔](https://docs.python.org/3/library/functions.html#filter)不會說「要拋出list()in」。 – unutbu
你指的是哪些在線文檔? 'b'意在表示你想要和不想要的'a'中的哪些值,即''b'是'a'上的一個掩模? – AChampion