首页 > 解决方案 > 如何在 Python 中的 list 对象中使用 where

问题描述

如何在 Python 中编写这样的东西?

AttributeError: 'list' 对象没有属性 'where'

results.where(result => result.varialbe is not None).ToList()

标签: python

解决方案


假设你的结果也是一个列表,你可以做这样的事情。

result = [1, 4, None, "foo"]

result_list = [variable for variable in result if variable is not None]

print(result_list)
# [1, 4, "foo"]

推荐阅读