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

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

相关推荐
databook22 分钟前
用方差阈值过滤掉“惰性特征”
python·机器学习·scikit-learn
Freak嵌入式23 分钟前
MCU 低功耗模式解析:时钟门控、电源门控、深度休眠
人工智能·python·单片机·嵌入式硬件·开源·依赖倒置原则·micropython
weixin_BYSJ19871 小时前
springboot校园自习室管理小程序---附源码32142
java·javascript·spring boot·python·django·flask·php
用户8356290780512 小时前
使用 Python 在 PDF 中绘制线条、矩形和自定义图形
后端·python
wang_yb2 小时前
用方差阈值过滤掉“惰性特征”
python·ai·databook
RFID固定资产管理系统4 小时前
公司RFID管理系统揭秘
大数据·python
IVEN_4 小时前
Python官方包、Conda、uv,应该怎么选
python
凡尘——雨落凡尘5 小时前
Python列表索引越界IndexError问题深度解析与解决办法
python·indexerror·list index out of range
Metaphor6925 小时前
使用 Python 在 Word 文档中添加或删除文本框
python·word
郝同学今天有进步吗6 小时前
构建 LangGraph Code Review Agent(七):实现规则匹配、Finding Guardrails 与 Markdown 报告
python·ai·fastapi·code review