社区所有版块导航
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 3中列表中的特定模式字符串

Gouse Shaik • 4 年前 • 798 次点击  

要求:使用regex只想从输入列表中获取特定的字符串,即“-”和“*”符号之间的字符串。下面是代码段

    ZTon = ['one-- and preferably only one --obvious', " Hello World", 'Now is better than never.', 'Although never is often better than *right* now.']
ZTon = [ line.strip() for line in ZTon]
print (ZTon)
r = re.compile(".^--")
portion = list(filter(r.match, ZTon)) # Read Note
print (portion)

预期响应:

['and preferably only one','right']
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38167
 
798 次点击  
文章 [ 3 ]  |  最新文章 4 年前