【问题标题】:Why does this filter function return an error in python? [duplicate]为什么这个过滤函数在python中返回错误? [复制]
【发布时间】:2019-11-07 18:32:40
【问题描述】:
list = ['hello','goodbye']
filteredList = list(filter(lambda x: x == "hello", list))
print(filteredList)

这会返回一个错误'list' object is not callable。 为什么是这样? 谢谢

【问题讨论】:

  • 因为你定义你是 python list,名称为 list。现在你的变量 list 正在掩盖内置的 list
  • 哦,是的!非常感谢,不知道我怎么没看到:)

标签: python


【解决方案1】:

将您的 list 变量重命名为其他名称,例如 llist 已经是 Python 中一个类的名称。

l = ['hello','goodbye']
shesaid = list(filter(lambda x: x == "AA", l))
print(shesaid)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2017-02-11
    • 1970-01-01
    • 2014-12-16
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多