python - 如何在 Python 中的 list 对象中使用 where
问题描述
如何在 Python 中编写这样的东西?
AttributeError: 'list' 对象没有属性 'where'
results.where(result => result.varialbe is not None).ToList()
解决方案
假设你的结果也是一个列表,你可以做这样的事情。
result = [1, 4, None, "foo"]
result_list = [variable for variable in result if variable is not None]
print(result_list)
# [1, 4, "foo"]
推荐阅读
- c - C - 如何在 realloc() 之后添加到 char 数组的末尾
- r - 重置 R Shiny 中 Shinyalert 的输入
- arrays - 如何重复列表中的元素n次?
- python - 将 docker 容器连接到 RDS 数据库
- google-cloud-platform - 为数组数据类型设置 `exclude_from_indexes`
- node.js - 如何将现有数据库更新为 RTL?
- javascript - React-Native:警告:未安装组件上的反应状态更新
- ios - Xcode/iOS:Launchscreen.storyboard 只能在 Objective-C 中编辑?
- javascript - 拆分空格并搜索用户输入
- github - "Resource not accessible by integration" when trying to create trigger