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
"""

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

相关推荐
程序员雷欧21 分钟前
LongAdder
开发语言·python
月光船幽幽31 分钟前
分层阈值规避归藏协议过度重置
人工智能·python
SMF191937 分钟前
【Linux】完美解决缩略图工具gm调用java.io.FileNotFoundException: gm问题
java·开发语言·python
㳺三才人子39 分钟前
初探 Data Analysis - Matplotlib
python·plotly·pandas·matplotlib
Python私教1 小时前
0、null、未采集:AI Agent 反馈系统最容易踩的语义坑
人工智能·python
北斗落凡尘1 小时前
LangGraph 入门实战(5)
python·langchain
Python私教1 小时前
请求超时不等于失败:把写操作恢复设计成事实回读
后端·python
且听风吟02201 小时前
7.包管理工具
python
程序员杰哥2 小时前
依赖于第三方接口时,如何进行测试?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
java修仙传2 小时前
从网页禅道到 AI 能调用的工具:我的禅道 MCP 实现思路分享
java·人工智能·python·ai应用·mcp开发