python - If any of the lines in a list of lines contains a substring
问题描述
Python 3.7.3
I have a list of lines and I want a single statement to test if a value is contained by any of the lines:
>>> data=[["red blue green yellow"],["peter ann jack beatrice"]]
>>> "ann" in data
False
I want this to be True.
Is there a single statement test, without explicit iteration, that will return True for "ann" or any of the single values in the two lists.
解决方案
'ann' in ' '.join(sum(data,[]))
推荐阅读
- r - R懒惰的评估 - 不工作
- javascript - d3:当一条线移动到特定位置时调用函数
- windows - 创建具有可扩展值的用户环境变量
- php - 出现警告后 PHP 脚本停止
- android - 单击后底部导航视图占用空间
- php - PHP检查“多维数组(数组([key] => value))”值是否为空
- xml -
失败并显示“名称和路径已存在的位置/作业” - html - 从手机查看时如何使用css裁剪图像?
- linux - 运行 sh 脚本会给出未找到任何 unix/linux 基本命令的命令
- javascript - 在 Ionic3 App 中应该首先运行什么混淆或缩小 javascript 代码