我有一个列表例如
list = [1,2,3,'t',4,5,'fgt',6,7,'string']
Run Code Online (Sandbox Code Playgroud)
我想使用该filter()函数删除所有字符串只留下数字.我可以用常规方法做到这一点,但我不能用过滤方法做任何提示?
所以:
list(filter(type(i)==str,a)))
Run Code Online (Sandbox Code Playgroud)
不会工作...我试图使用它,但仍然不起作用:
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
list(filter(type(a[-1])==str,a))
TypeError: 'bool' object is not callable
Run Code Online (Sandbox Code Playgroud)