社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

在python中将字符串中的字符与列表匹配

georgebills123 • 5 年前 • 1605 次点击  

前任:

>>>match(['hello', 'world'], "hold"])
>>>True

到目前为止我得到的是:

def match(myList , myString):
    for i in myList:
        "".join(str(i) for i in myList)
    for e in myString:
        if any(e == i):
            return True

但是我得到一个类型错误:“bool”对象不可iterable

编辑: 我让它这么做:

def match(myList, myString):
   listString = "".join(myList)
    return all(character in listString for character in myString)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54830
 
1605 次点击  
文章 [ 1 ]  |  最新文章 5 年前