python - 在 if 条件下使用两个 any 函数时出错
问题描述
这是一个非常简单(可能很愚蠢)的问题。但我已经尝试了一个小时。这是一个无效的语法语句,当我对任何函数使用两个 if 条件时。这是我使用的语句。
if any(table in sentence for table in (alias_dict["tables"].strip('][').split(', ')))==False and if any(column in sentence for column in (alias_dict["columns"].strip('][').split(', ')))==True:
print("Hii success")
但我收到错误:
如果有的话(句子中的表对于(alias_dict [“tables”].strip('] [').split(','))中的表)==False 并且如果有(句子中的列对于(alias_dict [”中的列) columns"].strip('][').split(', ')))==True: ^ SyntaxError: invalid syntax
错误 (^) 显示在“和”附近。我也尝试给出“&&”。我也尝试为整体any()
提供paranthesis。但它似乎没有成功。我知道这可能是我的一个愚蠢的错误。仍然感谢任何帮助。
解决方案
语法是if thing and otherthing
,不是if thing and if otherthing
。
比较起来False
也有点奇怪。试试这个。
if not any(
table in sentence for table in alias_dict["tables"].strip('][').split(', ')
) and any(
column in sentence for column in alias_dict["columns"].strip('][').split(', ')):
print("Hii success")
推荐阅读
- c - 输出不执行 C 中的所有代码,只是其中的一部分。也许问题不在于代码,而在于我的文本编辑器
- r - 我在 HTTR 中的 GET 响应不断出现错误,但能够通过 Postman 获得响应
- python - ValueError:计划形状未对齐 -> 使用 pd.concat() 时
- javascript - 为什么我的递归函数在没有通过逻辑测试的情况下进行递归(Javascript 函数帮助)?
- javascript - 使用平滑滚动条插件触发滚动事件的问题
- ffmpeg - FFMPEG 屏幕录制:如何使用 ffmpeg 和 xorg 获取 H265 (libx265) 录制?
- powershell - 如何在 txt 或 csv 文件中获取所有用户的 get-ADPrincipalGroupMembership 并将其放入每个用户的 txt 文件中?
- linux - 如何在 Linux 终端中使用 grep 命令获取四个字母单词的列表?
- javascript - 分离函数的JavaScript问题
- android - Android Studio 4.x 模拟器中缺少模拟器工具栏 3dot 模拟器设置菜单