Python 判断列表中是否有元素被另一字符串包含

Python 判断列表中是否有元素被另一字符串包含

推荐阅读

all() 函数与 any() 函数

正文

python 复制代码
lst = ['das', 'it']
str1 = 'dasAuto'

if any(text in str1 for text in lst):
    print('The string contains at least one element from the list')
else:
    print('The string does NOT contain any of the elements in the list')
"""
result:
The string contains at least one element from the list
"""

如果大家觉得有用,就请点个赞吧~

相关推荐
李帅5151 小时前
用 CPU 做发票识别:从 OCR 文本行到结构化明细表的 4 个硬骨头
python
happylifetree2 小时前
Python79:核心语法-面向对象基础-实例方法
python
贝壳6902 小时前
bool-hybrid-array 9.13.6 偷偷加了个"按键自动升序"的字典,我翻出来测了下
python
艺杯羹2 小时前
MCP本地服务集成避坑:从Stdio管道僵死到双向JSON-RPC稳健通信
人工智能·python·ai·系统架构·大语言模型·ai编程·mcp
happylifetree2 小时前
Python78:核心语法-面向对象基础-类与对象
python
duansamve3 小时前
Python中进程
python
日日大王学编程3 小时前
AI Agent 技术发展历程、演进逻辑与技术范式综述
人工智能·python
春涧草茶4 小时前
慢就是快16-1协程
开发语言·前端·python
5233AI开发笔记4 小时前
API 返回 429:先区分限速、并发和配额,再决定是否重试
python
databook4 小时前
经常听到的透视表是干什么的?
python·数据分析·pandas