python - 如何从 any() 函数中获取变量
问题描述
我正在寻找满足条件的 list_select 变量并在下一行进行追加。
我怎样才能使它在list_select.append(dupe)行中可用?
if any(list_select in dupe for list_select in pattern_dict):
list_select.append(dupe)
解决方案
你不能 with any
,它只返回一个布尔值。改用生成器表达式:
gen = (x for x in pattern_dict if x in dupe)
list_select = next(gen, None)
if list_select is not None:
...
推荐阅读
- c# - 如何部署 asp.net 核心应用程序以在没有 VM 机器的情况下使用无头浏览器?
- azure - 如何在 Blob Triggered Azure Function V 1.x 中添加对文件夹中所有 DLL 的引用?
- c# - 这种类型的 C# Docstring 可行吗?f 是的,我怎样才能让 Visual Studio 自动填充它,就像 eclipse 对 java Docstring 所做的那样?
- tensorflow - TensorFlow v1.4 急切执行
- rest - Microsoft Graph 获取直接下属的其他属性
- java - 如何修复“UUID 类型的方法参数缺少 URI 模板变量 'uuid'”?
- c# - EF Core DB 上下文跟踪生命周期和范围
- php - php 中已弃用的函数 create_function
- flutter - Flutter 如何使用数据列表创建水平可滚动的卡片视图
- java - 使用 WebPush Api 部署两次类似的战争导致 InvalidKeySpecException:无法识别密钥规范