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

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

相关推荐
名字还没想好☜23 分钟前
Python 字符编码实战:encode/decode、UnicodeDecodeError 与 open 的 encoding 坑
开发语言·后端·python·编程语言
带多刺的玫瑰32 分钟前
Leecode#29刷题之两数相除
java·python·算法
smj2302_7968265234 分钟前
解决leetcode第4017题数组中的峰值II
python·算法·leetcode
卷无止境39 分钟前
AI Agent编程中,重构节奏与安全检查的门道
后端·python
慧都小妮子44 分钟前
用 Python 批量把 PDF 参考文献排成 MLA 格式:Spire.Doc for Python 实战
python·pdf·c#·spire.doc·mla格式·参考文献排版·pdf批量处理
卷无止境1 小时前
AI编程时代,代码复杂性正在悄悄失控
后端·python
开源量化GO1 小时前
看到“2026年 Python 与 API”时,用示例和拆解看清关系
人工智能·python
高洁011 小时前
大模型是怎么“学会“的:预训练、微调、对齐三段论
python·深度学习·transformer·知识图谱·tornado
529宝宝起名网1 小时前
用 Python 开发名字五行八字匹配工具:从八字排盘到喜用神起名的全流程实现
python
砚底藏山河1 小时前
并发与限频工程:把20只的2秒压到0.5秒不封号(魔码量化实战 #03)
java·开发语言·数据库·python·金融